Skip to content
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

Add disallowedSuperglobals rule #105

Merged
merged 1 commit into from
Mar 27, 2022
Merged

Conversation

ekisu
Copy link
Contributor

@ekisu ekisu commented Mar 11, 2022

This adds a rule disallowedGlobals, which intends to disallow usages of variables such as $_GET or $_SERVER throughout the code. It might be helpful on some code bases which make extensive usage of those, instead of using things like the PSR-7 RequestInterface.

@spaze
Copy link
Owner

spaze commented Mar 15, 2022

Hey @ekisu and thanks for the PR. I quite like the idea and I have a few ideas/questions:

Would you like this to also report on other global variables? Like

function foo()
{
    global $bar;
}

If yes, then can you write a test for that? Or do you want this to report only superglobal ($_GET, $_POST, ...) usage? If this is the case, can you rename it (and the classes) to disallowSuperGlobals rule? I'm totally fine with either of those two options, maybe I even slightly prefer just renaming it to disallowSuperGlobals but it's really up to you. (And yeah, I've noticed the test for the "unknown" superglobal $TEST_GLOBAL_VARIABLE, and would like to preserve the test even if you just rename the thing.)

@ekisu
Copy link
Contributor Author

ekisu commented Mar 15, 2022

The idea originally was to report only on superglobals really, I've renamed the rule to disallowedSuperglobals (and the remaining of the code as well)

@ekisu ekisu changed the title Add disallowedGlobals rule Add disallowedSuperglobals rule Mar 15, 2022
@spaze
Copy link
Owner

spaze commented Mar 22, 2022

Got it, will check soon (next week or so, busy now, sorry!), thanks!

@spaze spaze self-requested a review March 22, 2022 03:56
@spaze spaze self-assigned this Mar 22, 2022
@spaze spaze merged commit 214b02a into spaze:master Mar 27, 2022
@spaze
Copy link
Owner

spaze commented Mar 27, 2022

Hey, thanks again 👍 I've added support for allowIn, made some minor cosmetic changes, squashed the commit and merged it. Will release soon.

@spaze
Copy link
Owner

spaze commented Mar 27, 2022

Released in 2.3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants