phpstan-banned-code icon indicating copy to clipboard operation
phpstan-banned-code copied to clipboard

Normalize leading backslashes in banned function names

Open spawnia opened this issue 4 years ago • 1 comments

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.

spawnia avatar Feb 18 '20 15:02 spawnia

@mremi do you mind taking a look at this PR?

spawnia avatar Apr 28 '20 14:04 spawnia