You are here

public function Drupal_Sniffs_Semantics_RemoteAddressSniff::process in Coder 7.2

Processes this test, when one of its tokens is encountered.

Parameters

PHP_CodeSniffer_File $phpcsFile The current file being processed.:

int $stackPtr The position of the current token: in the stack passed in $tokens.

Return value

void

File

coder_sniffer/Drupal/Sniffs/Semantics/RemoteAddressSniff.php, line 45

Class

Drupal_Sniffs_Semantics_RemoteAddressSniff
Make sure that the function ip_address() is used instead of $_SERVER['REMOTE_ADDR'].

Code

public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
  $string = $phpcsFile
    ->getTokensAsString($stackPtr, 4);
  if ($string === '$_SERVER["REMOTE_ADDR"]' || $string === '$_SERVER[\'REMOTE_ADDR\']') {
    $error = 'Use the function ip_address() instead of $_SERVER[\'REMOTE_ADDR\']';
    $phpcsFile
      ->addError($error, $stackPtr, 'RemoteAddress');
  }
}