@@ -55,18 +55,39 @@ public function register() {
5555 */
5656 public function process_token ( $ stackPtr ) {
5757
58- if ( $ this ->tokens [ $ stackPtr ]['content ' ] !== '$_SERVER ' ) {
59- // Not the variable we are looking for.
58+ if ( $ this ->tokens [ $ stackPtr ]['content ' ] !== '$_SERVER '
59+ && $ this ->tokens [ $ stackPtr ]['content ' ] !== '$GLOBALS '
60+ ) {
61+ // Not a variable we are looking for.
6062 return ;
6163 }
6264
65+ $ searchStart = $ stackPtr ;
66+ if ( $ this ->tokens [ $ stackPtr ]['content ' ] === '$GLOBALS ' ) {
67+ $ globalsIndexPtr = $ this ->get_array_access_key ( $ stackPtr );
68+ if ( $ globalsIndexPtr === false ) {
69+ // Couldn't find an array index token usable for the purposes of this sniff. Bow out.
70+ return ;
71+ }
72+
73+ $ globalsIndexName = TextStrings::stripQuotes ( $ this ->tokens [ $ globalsIndexPtr ]['content ' ] );
74+ if ( $ globalsIndexName !== '_SERVER ' ) {
75+ // Not access to `$GLOBALS['_SERVER']`.
76+ return ;
77+ }
78+
79+ // Set the start point for the next array access key search to the close bracket of this array index.
80+ // No need for defensive coding as we already know there will be a valid close bracket next.
81+ $ searchStart = $ this ->phpcsFile ->findNext ( Tokens::$ emptyTokens , ( $ globalsIndexPtr + 1 ), null , true );
82+ }
83+
6384 $ prevNonEmpty = $ this ->phpcsFile ->findPrevious ( Tokens::$ emptyTokens , ( $ stackPtr - 1 ), null , true );
6485 if ( $ this ->tokens [ $ prevNonEmpty ]['code ' ] === T_DOUBLE_COLON ) {
6586 // Access to OO property mirroring the name of the superglobal. Not our concern.
6687 return ;
6788 }
6889
69- $ indexPtr = $ this ->get_array_access_key ( $ stackPtr );
90+ $ indexPtr = $ this ->get_array_access_key ( $ searchStart );
7091 if ( $ indexPtr === false ) {
7192 // Couldn't find an array index token usable for the purposes of this sniff. Bow out as undetermined.
7293 return ;
0 commit comments