phpstan-disallowed-calls icon indicating copy to clipboard operation
phpstan-disallowed-calls copied to clipboard

disallowParamsAnywhere isn't supported

Open gms8994 opened this issue 8 months ago • 2 comments

First off, I love the flexibility that this library has. It's been quite beneficial for getting rid of specific uses of code in our systems.

There may be another way to do this, but from reading the documentation, I can't seem to figure out a way; I want to disallow all calls to Object->method but only if the parameter is 'my-test-string'. method however can take a string, an array of values, or a destructured array of values. So I want disallowParamsAnywhere, specifically for the destructured array case.

disallowParams is a partial workaround, and will allow us to catch the obvious cases, but having support for catching them anywhere would be awesome!

gms8994 avatar May 28 '25 20:05 gms8994

Hi, I'm happy to hear this little thing helps! :-)

Do you mean that you'd like to detect and disallow a call that looks like these:

$object->method('my-test-string');
$object->method([123, 'foo', 'my-test-string']);
$object->method([4 => 56, 'foo' => new SomeClass, 'my-test-string']);

... but these would be fine:

$object->method('something');
$object->method([123, 'foo', 'bat']);
$object->method([4 => 56, 'foo' => new SomeClass, 'waldo']);

spaze avatar May 29 '25 12:05 spaze

You're spot on! I'm sure the array piece makes it more difficult, of course :D

gms8994 avatar May 29 '25 14:05 gms8994