class RemoteAddressSniff in Coder 8.2
Same name and namespace in other branches
- 8.3 coder_sniffer/Drupal/Sniffs/Semantics/RemoteAddressSniff.php \Drupal\Sniffs\Semantics\RemoteAddressSniff
- 8.3.x coder_sniffer/Drupal/Sniffs/Semantics/RemoteAddressSniff.php \Drupal\Sniffs\Semantics\RemoteAddressSniff
Make sure that the function ip_address() is used instead of $_SERVER['REMOTE_ADDR'].
@category PHP @package PHP_CodeSniffer @link http://pear.php.net/package/PHP_CodeSniffer
Hierarchy
- class \Drupal\Sniffs\Semantics\RemoteAddressSniff implements \PHP_CodeSniffer\Sniffs\Sniff
Expanded class hierarchy of RemoteAddressSniff
File
- coder_sniffer/
Drupal/ Sniffs/ Semantics/ RemoteAddressSniff.php, line 23
Namespace
Drupal\Sniffs\SemanticsView source
class RemoteAddressSniff implements Sniff {
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register() {
return array(
T_VARIABLE,
);
}
//end register()
/**
* Processes this test, when one of its tokens is encountered.
*
* @param \HP_CodeSniffer\Files\File $phpcsFile The current file being processed.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process(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');
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RemoteAddressSniff:: |
public | function | Processes this test, when one of its tokens is encountered. | |
RemoteAddressSniff:: |
public | function | Returns an array of tokens this test wants to listen for. |