Repository navigation
Conversation
c8ec7bb to
21c42f6
Compare
|
Please report a issue with a reproducer showcasing the problem you are trying to fix. |
|
Reported with reproducer as requested: phpstan/phpstan#15494. Thank you! |
|
|
||
| public function test(): void | ||
| { | ||
| $a = [$this, 'method']; |
There was a problem hiding this comment.
doesn't work for
$a = [$this, rand(0, 1) ? 'method' : 'someOther'];
or
$m = rand(0, 1) ? 'method' : 'someOther';
$a = [$this, $m];
|
just because phpstan-src itself is fine just with the private-method-calls, this might not apply in general. |
|
Closing this. After measuring it again I consider the change too risky for too little benefit: on the reproducer from phpstan/phpstan#15494 it brings no measurable improvement, and a narrower variant I tried introduced a false positive. Thanks for taking the time to look at it. |
Fixes phpstan/phpstan#15494
In
ClassStatementsGatherer, any 2-element array is unconditionally added to->methodCalls. When a class defines at least one unused private method,UnusedPrivateMethodRuleevaluates->isCallable()on every gathered array in the class. For 2-element data arrays whose first element names a class,ConstantArrayType::isCallable()triggers reflection on that class, even though private methods of the current class can only be called on ``,self, `static`, or the declaring class name.Reproducer
See phpstan/phpstan#15494
Expected Behavior
Two-element arrays whose first item is not ``,
self::class, `static::class`, `ClassName::class` (matching the current class), or `::class` should not be gathered into `ClassStatementsGatherer::`. This avoids reflecting unrelated classes as callable targets during unused private method analysis.