phpstan-banned-code
phpstan-banned-code copied to clipboard
Normalize leading backslashes in banned function names
I stumbled upon this when trying to ban the use of sprintf
in our project. Because we are using the amazing https://github.com/thecodingmachine/safe, we also have to ban \Safe\printf
.
The configuration looks like this:
banned_code:
nodes:
- type: Expr_FuncCall
functions:
- sprintf
- \Safe\sprintf
What happened is that \Safe\sprintf
was not found. Upon further investigation, i found that php-parser
strips leading backslashes from function calls, even when they occur in the source code.
To avoid this hard to find error, i applied the same normalization to the banned functions definitions from the configuration file.
@mremi do you mind taking a look at this PR?