-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
False Positives on disallowedFunctionCalls Rule in Version 4.1.1 #288
Comments
Hi, this case is actually tested for quite some time already:
phpstan-disallowed-calls/tests/Calls/FunctionCallsTest.php Lines 49 to 53 in c921da2
Then in the tested file there's also
But there's no error reported on line 17: phpstan-disallowed-calls/tests/Calls/FunctionCallsTest.php Lines 240 to 247 in c921da2
4.1.0 (and 4.1.1) has started detecting disallowed calls also in callables (e.g.
|
PHPStan 2.x says that the "expected" param of the
https://github.com/spaze/phpstan-disallowed-calls/actions/runs/12911818495/job/36005135640#step:6:19 And because phpstan-disallowed-calls/src/RuleErrors/DisallowedCallableParameterRuleErrors.php Lines 90 to 92 in c921da2
And If the param wouldn't be reported as callable, then this condition here would be false and no error would be reported: phpstan-disallowed-calls/src/RuleErrors/DisallowedCallableParameterRuleErrors.php Lines 178 to 180 in c921da2
PHPStan 1.12 doesn't report the parameter to be callable and the test passes (marked as risky though because of the vardumps):
Honestly, I don't know what needs to be changed here, if anything in this extension. |
Not a bug here 👍 |
Maybe @ondrejmirtes could shed some light on why PHPStan 2.x shows This is the test subject ( and the testcase here: Running |
I know! You're trying to get the signatures of PHPUnit's This is how the signature looks like: /**
* @template ExpectedType
* @param ExpectedType $expected
* @throws ExpectationFailedException
* @phpstan-assert =ExpectedType $actual
*/
final public static function assertSame(mixed $expected, mixed $actual, string $message = ''): void You're doing: $parametersAcceptor = ParametersAcceptorSelector::selectFromArgs($scope, $node->getArgs(), $reflection->getVariants()); Which triggers the whole generics type inference. What you get back for this call /**
* @param 'foobar' $expected
* @throws ExpectationFailedException
* @phpstan-assert ='foobar' $actual
*/
final public static function assertSame(mixed $expected, mixed $actual, string $message = ''): void So when you ask for the type of In PHPStan 1.x (without bleeding edge) you'd just get As a possible fix you should just get |
Wow, excellent! Thanks @ondrejmirtes for the analysis and the proposed fix, it works and doesn't report errors in the |
As suggested in #288 (comment) Close #288
I've released the fix in 4.2.1 now, @yoannblot please let me know if it works as expected now. |
It works like a charm! Thank you so much @spaze & @ondrejmirtes ❤ ! |
Description
Summary:
After upgrading from version
4.0.1
to4.1.1
, thedisallowedFunctionCalls
rule produces false positives when certain strings are present in method names, incorrectly identifying them as forbidden function calls.Steps to Reproduce:
Configure
disallowedFunctionCalls
as follows:Define a method or function with a name that includes the substring of a forbidden function, such as
testItHandlesSomeOptional()
.Run
PHPStan
analysis.Observed Behavior:
PHPStan flags the method as violating the
disallowedFunctionCalls
rule:Expected Behavior:
PHPStan
should not flag method or function names that merely include substrings matching forbidden function names. Only actual calls to the forbidden functions should trigger a violation.Environment:
PHPStan version: 2.1.1
spaze/phpstan-disallowed-calls: 4.1.1
Previous working version: 4.0.1
Additional Notes:
This appears to be a regression introduced in version
4.1.1
. The pattern matching for thedisallowedFunctionCalls
rule seems to be overly aggressive, treating method or function names as if they were calls to the forbidden functions.Let me know if more details are needed!
The text was updated successfully, but these errors were encountered: