Implement MagicClassConstantRule#2741
Conversation
d610eb2 to
0b186a6
Compare
conf/config.level0.neon
Outdated
There was a problem hiding this comment.
This should be enabled only with bleeding edge. The code does not error, it just returns an empty string AFAIK.
There was a problem hiding this comment.
I have used a feature flag with a more general name, so I can use it for similar rules for __FUNCTION__ and __METHOD__
There was a problem hiding this comment.
The message should be different. It just returns an empty string.
|
Can you also please go through other magic constants and report them when used in a wrong way? Maybe it can all be done inside this single rule. |
5ef5af0 to
92c94d4
Compare
|
there is one interessting leftover case: // test.php
function doFooParams(
string $file = __FILE__,
int $line = __LINE__,
string $class = __CLASS__,
string $dir = __DIR__,
string $namespace = __NAMESPACE__,
string $method = __METHOD__,
string $function = __FUNCTION__,
string $trait = __TRAIT__
): void
{
}since used in the parameter-list and not the function body it false-positives with |
|
we could fix the above case by moving phpstan-src/src/Analyser/NodeScopeResolver.php Lines 451 to 459 in 231ed3e wdyt? |
909ab5d to
842d371
Compare
staabm
left a comment
There was a problem hiding this comment.
Instead of changing NodeScopeResolver I went with adding a dedicated new NodeVisitor to prevent the false positives
8e518b0 to
85473c8
Compare
There was a problem hiding this comment.
Please deleted "when used" from all messages. They'll still make sense.
c1172f6 to
9191a31
Compare
|
(btw: interessting that issuebot did not realize that the snippet from issue phpstan/phpstan#10099 gets a new error with this PR - locally it works as expected though) |
There was a problem hiding this comment.
This doesn't seem right. What about private $foo = __METHOD__;?
Also a false positive here - you can have an anonymous function outside a class/function and it's going to report '{closure}'.
9191a31 to
4ff7c84
Compare
4ff7c84 to
5e4d878
Compare
|
Thank you. |
closes phpstan/phpstan#10099
background: https://www.php.net/manual/en/language.constants.magic.php