protected function process_global_statement( $stackPtr, $in_function_scope ) {
		/*
		 * Collect the variables to watch for.
		 */
		$search = array();
		$ptr    = ( $stackPtr + 1 );
		while ( isset( $this->tokens[ $ptr ] ) ) {
			$var = $this->tokens[ $ptr ];

			// Halt the loop at end of statement.
			if ( \T_SEMICOLON === $var['code'] ) {
				break;
			}

			if ( \T_VARIABLE === $var['code'] ) {
				if ( isset( $this->wp_globals[ substr( $var['content'], 1 ) ] ) ) {
					$search[] = $var['content'];
				}
			}

			$ptr++;
		}
		unset( $var );

		if ( empty( $search ) ) {
			return;
		}

		/*
		 * Search for assignments to the imported global variables within the relevant scope.
		 */
		$start = $ptr;
		if ( true === $in_function_scope ) {
			$function_cond = $this->phpcsFile->getCondition( $stackPtr, \T_FUNCTION );
			$closure_cond  = $this->phpcsFile->getCondition( $stackPtr, \T_CLOSURE );
			$scope_cond    = max( $function_cond, $closure_cond ); // If false, it will evaluate as zero, so this is fine.
			if ( isset( $this->tokens[ $scope_cond ]['scope_closer'] ) === false ) {
				// Live coding or parse error.
				return;
			}
			$end = $this->tokens[ $scope_cond ]['scope_closer'];
		} else {
			// Global statement in the global namespace with file is being treated as scoped.
			$end = ( $this->phpcsFile->numTokens + 1 );
		}

		for ( $ptr = $start; $ptr < $end; $ptr++ ) {

			// Skip over nested functions, classes and the likes.
			if ( isset( $this->skip_over[ $this->tokens[ $ptr ]['code'] ] ) ) {
				if ( ! isset( $this->tokens[ $ptr ]['scope_closer'] ) ) {
					// Live coding or parse error.
					break;
				}

				$ptr = $this->tokens[ $ptr ]['scope_closer'];
				continue;
			}

			if ( \T_VARIABLE !== $this->tokens[ $ptr ]['code'] ) {
				continue;
			}

			if ( \in_array( $this->tokens[ $ptr ]['content'], $search, true ) === false ) {
				// Not one of the variables we're interested in.
				continue;
			}

			// Don't throw false positives for static class properties.
			if ( $this->is_class_object_call( $ptr ) === true ) {
				continue;
			}

			if ( true === $this->is_assignment( $ptr ) ) {
				$this->maybe_add_error( $ptr );
				continue;
			}

			// Check if this is a variable assignment within a `foreach()` declaration.
			if ( $this->is_foreach_as( $ptr ) === true ) {
				$this->maybe_add_error( $ptr );
			}
		}
	}
protected function process_global_statement( $stackPtr, $in_function_scope ) {
		/*
		 * Collect the variables to watch for.
		 */
		$search = array();
		$ptr    = ( $stackPtr + 1 );
		while ( isset( $this->tokens[ $ptr ] ) ) {
			$var = $this->tokens[ $ptr ];

			// Halt the loop at end of statement.
			if ( \T_SEMICOLON === $var['code'] ) {
				break;
			}

			if ( \T_VARIABLE === $var['code'] ) {
				if ( isset( $this->wp_globals[ substr( $var['content'], 1 ) ] ) ) {
					$search[] = $var['content'];
				}
			}

			$ptr++;
		}
		unset( $var );

		if ( empty( $search ) ) {
			return;
		}

		/*
		 * Search for assignments to the imported global variables within the relevant scope.
		 */
		$start = $ptr;
		if ( true === $in_function_scope ) {
			$function_cond = $this->phpcsFile->getCondition( $stackPtr, \T_FUNCTION );
			$closure_cond  = $this->phpcsFile->getCondition( $stackPtr, \T_CLOSURE );
			$scope_cond    = max( $function_cond, $closure_cond ); // If false, it will evaluate as zero, so this is fine.
			if ( isset( $this->tokens[ $scope_cond ]['scope_closer'] ) === false ) {
				// Live coding or parse error.
				return;
			}
			$end = $this->tokens[ $scope_cond ]['scope_closer'];
		} else {
			// Global statement in the global namespace with file is being treated as scoped.
			$end = ( $this->phpcsFile->numTokens + 1 );
		}

		for ( $ptr = $start; $ptr < $end; $ptr++ ) {

			// Skip over nested functions, classes and the likes.
			if ( isset( $this->skip_over[ $this->tokens[ $ptr ]['code'] ] ) ) {
				if ( ! isset( $this->tokens[ $ptr ]['scope_closer'] ) ) {
					// Live coding or parse error.
					break;
				}

				$ptr = $this->tokens[ $ptr ]['scope_closer'];
				continue;
			}

			if ( \T_VARIABLE !== $this->tokens[ $ptr ]['code'] ) {
				continue;
			}

			if ( \in_array( $this->tokens[ $ptr ]['content'], $search, true ) === false ) {
				// Not one of the variables we're interested in.
				continue;
			}

			// Don't throw false positives for static class properties.
			if ( $this->is_class_object_call( $ptr ) === true ) {
				continue;
			}

			if ( true === $this->is_assignment( $ptr ) ) {
				$this->maybe_add_error( $ptr );
				continue;
			}

			// Check if this is a variable assignment within a `foreach()` declaration.
			if ( $this->is_foreach_as( $ptr ) === true ) {
				$this->maybe_add_error( $ptr );
			}
		}
	}
protected function process_global_statement ( $ stackPtr , $ in_function_scope ) { /*
		 * Collect the variables to watch for.
		 */ $ search = array ( ) ; $ ptr = ( $ stackPtr + 1 ) ; while ( isset ( $ this -> tokens [ $ ptr ] ) ) { $ var = $ this -> tokens [ $ ptr ] ; // Halt the loop at end of statement. if ( \ T_SEMICOLON === $ var [ 'code' ] ) { break ; } if ( \ T_VARIABLE === $ var [ 'code' ] ) { if ( isset ( $ this -> wp_globals [ substr ( $ var [ 'content' ] , 1 ) ] ) ) { $ search [ ] = $ var [ 'content' ] ; } } $ ptr ++ ; } unset ( $ var ) ; if ( empty ( $ search ) ) { return ; } /*
		 * Search for assignments to the imported global variables within the relevant scope.
		 */ $ start = $ ptr ; if ( true === $ in_function_scope ) { $ function_cond = $ this -> phpcsFile -> getCondition ( $ stackPtr , \ T_FUNCTION ) ; $ closure_cond = $ this -> phpcsFile -> getCondition ( $ stackPtr , \ T_CLOSURE ) ; $ scope_cond = max ( $ function_cond , $ closure_cond ) ; // If false, it will evaluate as zero, so this is fine. if ( isset ( $ this -> tokens [ $ scope_cond ] [ 'scope_closer' ] ) === false ) { // Live coding or parse error. return ; } $ end = $ this -> tokens [ $ scope_cond ] [ 'scope_closer' ] ; } else { // Global statement in the global namespace with file is being treated as scoped. $ end = ( $ this -> phpcsFile -> numTokens + 1 ) ; } for ( $ ptr = $ start ; $ ptr < $ end ; $ ptr ++ ) { // Skip over nested functions, classes and the likes. if ( isset ( $ this -> skip_over [ $ this -> tokens [ $ ptr ] [ 'code' ] ] ) ) { if ( ! isset ( $ this -> tokens [ $ ptr ] [ 'scope_closer' ] ) ) { // Live coding or parse error. break ; } $ ptr = $ this -> tokens [ $ ptr ] [ 'scope_closer' ] ; continue ; } if ( \ T_VARIABLE !== $ this -> tokens [ $ ptr ] [ 'code' ] ) { continue ; } if ( \ in_array ( $ this -> tokens [ $ ptr ] [ 'content' ] , $ search , true ) === false ) { // Not one of the variables we're interested in. continue ; } // Don't throw false positives for static class properties. if ( $ this -> is_class_object_call ( $ ptr ) === true ) { continue ; } if ( true === $ this -> is_assignment ( $ ptr ) ) { $ this -> maybe_add_error ( $ ptr ) ; continue ; } // Check if this is a variable assignment within a `foreach()` declaration. if ( $ this -> is_foreach_as ( $ ptr ) === true ) { $ this -> maybe_add_error ( $ ptr ) ; } } }
Check that global variables imported into a function scope using a global statement
are not being overruled.

@since 1.1.0 Logic was previously contained in the process_token() method.

@param int  $stackPtr          The position of the current token in the stack.
@param bool $in_function_scope Whether the global statement is within a scoped function/closure.

@return void
Check that global variables imported into a function scope using a global statement are not being overruled .