spaze / phpstan-disallowed-calls

PHPStan rules to detect disallowed method & function calls, constant, namespace, attribute & superglobal usages
MIT License
255 stars 17 forks source link

`disallowedSuperglobals` with `allowIn` doesn't seem to work when referencing a trait #106

Closed ruudk closed 2 years ago

ruudk commented 2 years ago

I'm trying out the new disallowedSuperglobals rule while allowing a use inside trait:

parameters:
    disallowedSuperglobals:
        -
            superglobal: '$_SERVER'
            message: 'use <fg=yellow>Symfony\Component\HttpFoundation\Request</> object instead'
            allowIn:
                - **/src/Infrastructure/Persistence/Doctrine/DBAL/QueryBuffering.php
                - **/src/Kernel.php

It seems that the fix for traits doesn't work for super globals.

I get this error:

Using $_SERVER is forbidden, use Symfony\Component\HttpFoundation\Request object instead
↳ src/Core/SearchBundle/CliCommand/IndexUsersCommand.php:24
↳ src/Infrastructure/Persistence/.../DBAL/QueryBuffering.php:24

/cc @ekisu @spaze

spaze commented 2 years ago

Oh, nice catch! Seems the code with the fix is not even called in the superglobals helper, dooooh. Guess this calls for a helper helper 🤪 Will see if the helpers can be refactored somehow.

spaze commented 2 years ago

Thanks again for catching the problem. I've moved a few bits and bytes there and back (mostly there tho) and released 2.3.1, please let me know if that works for you - it should buuuuuut... :-)

ruudk commented 2 years ago

@spaze Just tested it and it works. Thanks for the fast fix ⚡ 💙