-
-
Notifications
You must be signed in to change notification settings - Fork 40
[RFC] Add PHPStan rules for forbidden methods and unnecessary named arguments #209
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
Conversation
- Add ForbiddenMethodCallsRule to prevent debugging functions like dump(), var_dump(), print_r(), dd() in production code - Add ForbidUnnecessaryNamedArgumentsRule to detect unnecessary named arguments when all parameters are provided in correct order - Support function calls, method calls, and constructor calls - Handle mixed positional and named arguments - Register both rules in extension.neon for automatic enforcement across all components 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
* @implements Rule<FuncCall> | ||
* @author Claude <[email protected]> | ||
*/ | ||
final class ForbiddenMethodCallsRule implements Rule |
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.
You could consider using https://github.com/spaze/phpstan-disallowed-calls for this.
@@ -28,6 +28,7 @@ | |||
* for better error handling and consistency across the Symfony AI monorepo. | |||
* | |||
* @implements Rule<Node> | |||
* @author Claude <[email protected]> |
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 removed
* @implements Rule<Node> | ||
* @author Claude <[email protected]> | ||
*/ | ||
final class ForbidUnnecessaryNamedArgumentsRule implements Rule |
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.
Sounds like a nice one for phpstan official repo 🙂
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 was rather thinking of PHP CS Fixer - feels a bit too opinionated and more about style than types
Thanks @OskarStark & @derrabus for having a look! Would you in general agree on that rule about named arguments or is it too opinionated? |
What does the rule do? Forbid the usage of named arguments if I could've made the same call with ordered arguments? It is opinionated all right. Not sure what you're trying to solve. If I have a value object like this: final readonly class Foo {
public function __construct(
public string $a,
public string $b,
public string $c,
) {}
} Then I wouldn't be allowed to do this? $foo = new Foo(
a: 'some value',
b: 'some value',
c: 'some value',
); Meh. |
To be honest, I just don't want to think about it while reviewing code 😬
Yup, and it's not that I care to much, but was thinking that's the easier rule. But if we don't mind in general, I can just drop thinking about it while reviewing 😆 |
no real need, let's close it |
I wanted to catch some stuff that a) happens to me and b) could be a rule to enforce while working with named arguments if you ask me.
🤖 Generated with Claude Code