Error on references of PHPStan internal class names#2932
Error on references of PHPStan internal class names#2932ondrejmirtes merged 3 commits intophpstan:1.10.xfrom
Conversation
bc19a7d to
0e839bd
Compare
|
This pull request has been marked as ready for review. |
|
Similar problems can happen on other popular tools, e.g. Rector. |
|
Thank you, I love this! I wonder if we could detect it automatically but then we're in the https://github.com/shipmonk-rnd/composer-dependency-analyser area so probably not worth it. I'd hardcode:
|
src/Rules/ClassNameCheck.php
Outdated
| $errors = []; | ||
|
|
||
| if ($checkClassCaseSensitivity) { | ||
| $errors += $this->classCaseSensitivityCheck->checkClassNames($pairs); |
There was a problem hiding this comment.
I don't really like doing + here. I'd rather iterate over the array and add the error one-by-one with $errors[] = ....
| 'Internal %s Class cannot be referenced: %s.', | ||
| $projectName, | ||
| $className, | ||
| ))->line($pair->getNode()->getLine())->build(); |
| } | ||
|
|
||
| $errors[] = RuleErrorBuilder::message(sprintf( | ||
| 'Internal %s Class cannot be referenced: %s.', |
There was a problem hiding this comment.
Please rewrite this as: "Referencing prefixed PHPStan class: _PHPStan_d5242a5\Symfony/Finder"
And add a tip without the prefix: "This is most likely unintentional. Did you mean to type Symfony\Finder?"
d98a636 to
e1cf9c3
Compare
e1cf9c3 to
254c757
Compare
|
Thank you! |
As discussed in phpstan/phpstan#10587 (comment) this PR adds a new
ClassForbiddenNameCheckwhich reports errors when code references a PHPStan prefixed class from a phpstan.phar file