{"action":"opened","issue":{"url":"https://api.github.com/repos/phpstan/phpstan/issues/397","repository_url":"https://api.github.com/repos/phpstan/phpstan","labels_url":"https://api.github.com/repos/phpstan/phpstan/issues/397/labels{/name}","comments_url":"https://api.github.com/repos/phpstan/phpstan/issues/397/comments","events_url":"https://api.github.com/repos/phpstan/phpstan/issues/397/events","html_url":"https://github.com/phpstan/phpstan/issues/397","id":244917703,"number":397,"title":"How to describe method returning object or array of objects?","user":{"login":"orls","id":155430,"avatar_url":"https://avatars3.githubusercontent.com/u/155430?v=4","gravatar_id":"","url":"https://api.github.com/users/orls","html_url":"https://github.com/orls","followers_url":"https://api.github.com/users/orls/followers","following_url":"https://api.github.com/users/orls/following{/other_user}","gists_url":"https://api.github.com/users/orls/gists{/gist_id}","starred_url":"https://api.github.com/users/orls/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/orls/subscriptions","organizations_url":"https://api.github.com/users/orls/orgs","repos_url":"https://api.github.com/users/orls/repos","events_url":"https://api.github.com/users/orls/events{/privacy}","received_events_url":"https://api.github.com/users/orls/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-07-23T15:37:25Z","updated_at":"2017-07-23T15:37:25Z","closed_at":null,"body":"I have some legacy external code that I'm trying to hint to PHPStan with a `MethodReflection` extension. The method in question returns either a single instance of `SomeClass` when only one is available, or an array of `SomeClass` instances when >1. Awkward, I know...😞.\r\n\r\nIn PHPStan 0.6.4 I was able to do the following in my MethodReflection implementation:\r\n\r\n```php\r\n    // ...\r\n    public function getReturnType(): Type\r\n    {\r\n        $retType = new ObjectType(SomeClass::class);\r\n        return new CommonUnionType([\r\n            $retType,\r\n            new ArrayType($retType)\r\n        ]);\r\n    }\r\n    // ...\r\n```\r\n\r\nHowever, in 0.7 this causes:\r\n\r\n```\r\n         Internal error: Cannot create PHPStan\\Type\\CommonUnionType with:\r\n         SomeClass,\r\n         SomeClass[]\r\n```\r\n\r\n...due to the [constructor changes](https://github.com/phpstan/phpstan/blob/8da03c084b2c8e4a92d48f6926f6191c2c7783ad/src/Type/CommonUnionType.php).\r\n\r\nMy current workaround is to just return `MixedType` – is there a more \"proper\"/formal constrained way to do this in >0.7?"}}
{"actor":{"display_login":"orls"}}