phpqa --analyzedDirs src/phpstan --output cli --tools phpstan
Output
------ --------------------------------------------------------------------------
Line phpstan/MethodAnnotations.php
------ --------------------------------------------------------------------------
10 Call to an undefined method Whatever\Swift_SmtpTransport::setUsername().
14 Call to an undefined method Whatever\Swift_SmtpTransport::setUsername().
------ --------------------------------------------------------------------------
------ -----------------------------------------------------------
Line phpstan/Proxy.php
------ -----------------------------------------------------------
29 Property Whatever\Proxy::$pdo (null) does not accept PDO.
30 Cannot call method setAttribute() on null.
------ -----------------------------------------------------------
------ ------------------------------------------------------------------------------
Line phpstan/Singleton.php
------ ------------------------------------------------------------------------------
14 Static property Whatever\Singleton::$facade (null) does not accept stdClass.
------ ------------------------------------------------------------------------------
[ERROR] Found 5 errors
PHPStan does not yet read method/property annotations on classes yet. It will be possible in some future version through regular expression configuration. The problem is that there's no standard, everyone writes these annotations in a different way and sometimes they are even missing some crucial information like arguments or return types.
For now, you can fix this by implementing your own class reflection extension. Here's a discussion about it.
The other errors are caused by the fact that in PHPStan, you can "cast" any expression to a different type using
instanceof
andis_*
functions. So inside theis_null
branch, PHPStan thinks that$this–>pdo
andself::$facade
have typenull
and nothing else can be assigned to them. It also works with negated condition:I now realize that in case of properties, this is not ideal, but not yet sure how to solve this. As a quick fix, you can use strict comparison with null instead: