New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error on references of PHPStan internal class names #2932
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be non-ignorable.
} | ||
|
||
$errors[] = RuleErrorBuilder::message(sprintf( | ||
'Internal %s Class cannot be referenced: %s.', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
ClassForbiddenNameCheck
which reports errors when code references a PHPStan prefixed class from a phpstan.phar file