phpstan-prophecy icon indicating copy to clipboard operation
phpstan-prophecy copied to clipboard

phpstan returning Cannot call method willReturn() on array<>.

Open nfebe opened this issue 3 years ago • 1 comments

Steps required to reproduce the problem :

Not sure this is an "issue' however, phpstan considers a call such as $this->packageRepositoryProphecy->findModules()->willReturn([]); problematic since findModules most often that not return something which is not an object.

Expected Result

Installing phpstan-phrophecy should tell phpstan to ingore such as it is a prophecy.

Actual Result

Not ignored.

More context : https://github.com/phpstan/phpstan/discussions/4599

nfebe avatar Feb 26 '21 23:02 nfebe

The issue is your type PackageRepository|ObjectProphecy on your packageRepositoryProphecy. That object does not contain a PackageRepository (and calling findModules on a PackageRepository will indeed return an array so phpstan is right about the reported issue). Your phpdoc should use @var ObjectProphecy<PackageRepository> instead.

stof avatar Dec 08 '21 11:12 stof

@jseparovic1 this should be closed as the solution is provided in my comment from 2021

stof avatar Mar 13 '24 15:03 stof

As I'm not maintainer of this library I'm forwarding friendly ping to @alexander-schranz to take a look.

jseparovic1 avatar Mar 13 '24 15:03 jseparovic1

oh sorry. I messed up who was the new maintainer

stof avatar Mar 13 '24 15:03 stof