spaze / phpstan-disallowed-calls

PHPStan rules to detect disallowed method & function calls, constant, namespace, attribute & superglobal usages
MIT License
263 stars 17 forks source link

Make sure that trait is analysed #226

Closed ondrejmirtes closed 11 months ago

ondrejmirtes commented 11 months ago

This is a response to: https://github.com/phpstan/phpstan/discussions/10268

To me it seemed you were everything correctly, so I checked it out. PHPStan needs to find the classes you're using in tests, which usually isn't a problem because they're simply in analysed paths, but the reflection in tests needs some extra help discovering them. I usually do that by adding tests directory into classmap in autoload-dev.

Now the output is:

vendor/bin/phpunit tests/Usages/AttributeUsagesTest.php --filter testTraits
PHPUnit 10.5.2 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.2.12
Configuration: /Users/ondrej/Development/spaze-phpstan-disallowed-calls/phpunit.xml

string(21) "PHPStan\Node\FileNode"
string(28) "PhpParser\Node\Stmt\Declare_"
string(34) "PhpParser\Node\Stmt\DeclareDeclare"
string(29) "PhpParser\Node\Scalar\LNumber"
string(30) "PhpParser\Node\Stmt\Namespace_"
string(26) "PhpParser\Node\Stmt\Trait_"
string(26) "PhpParser\Node\Stmt\Class_"
string(24) "PHPStan\Node\InClassNode"
string(28) "PhpParser\Node\Stmt\TraitUse"
string(24) "PHPStan\Node\InTraitNode"
string(30) "PhpParser\Node\Stmt\ClassConst"
string(24) "PhpParser\Node\Attribute"
string(29) "PhpParser\Node\AttributeGroup"
string(21) "PhpParser\Node\Const_"
string(30) "PhpParser\Node\Expr\ConstFetch"
string(28) "PhpParser\Node\Stmt\Property"
string(24) "PhpParser\Node\Attribute"
string(29) "PhpParser\Node\AttributeGroup"
string(36) "PhpParser\Node\Stmt\PropertyProperty"
string(30) "PHPStan\Node\ClassPropertyNode"
string(31) "PhpParser\Node\Stmt\ClassMethod"
string(24) "PhpParser\Node\Attribute"
string(29) "PhpParser\Node\AttributeGroup"
string(24) "PhpParser\Node\Attribute"
string(29) "PhpParser\Node\AttributeGroup"
string(20) "PhpParser\Node\Param"
string(25) "PhpParser\Node\Identifier"
string(25) "PhpParser\Node\Identifier"
string(30) "PHPStan\Node\InClassMethodNode"
string(29) "PHPStan\Node\ExecutionEndNode"
string(39) "PHPStan\Node\MethodReturnStatementsNode"
string(32) "PHPStan\Node\ClassPropertiesNode"
string(29) "PHPStan\Node\ClassMethodsNode"
string(31) "PHPStan\Node\ClassConstantsNode"
spaze commented 11 months ago

Oh shoot, wow, I was thiiis close :-) Thanks a lot!

I feel very bad now, because I actually load the files that are required for tests here https://github.com/spaze/phpstan-disallowed-calls/blob/f0a6f698e6bd3535423fca1807fa78f91c206af3/tests/bootstrap.php#L4-L7 and even have a test that checks that all files from the lib dir are loaded in bootstrap.php https://github.com/spaze/phpstan-disallowed-calls/blob/f0a6f698e6bd3535423fca1807fa78f91c206af3/tests/BootstrapTest.php#L26 but it's been proved useless now 😅 The classmap seems better.

Thanks again 🍻

spaze commented 11 months ago

I've added the composer.json change to #227 and the rest is in #225.