comparison vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Semantics/RemoteAddressSniff.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 129ea1e6d783
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2 /**
3 * Drupal_Sniffs_Semantics_RemoteAddressSniff.
4 *
5 * @category PHP
6 * @package PHP_CodeSniffer
7 * @link http://pear.php.net/package/PHP_CodeSniffer
8 */
9
10 /**
11 * Make sure that the function ip_address() is used instead of
12 * $_SERVER['REMOTE_ADDR'].
13 *
14 * @category PHP
15 * @package PHP_CodeSniffer
16 * @link http://pear.php.net/package/PHP_CodeSniffer
17 */
18 class Drupal_Sniffs_Semantics_RemoteAddressSniff implements PHP_CodeSniffer_Sniff
19 {
20
21
22 /**
23 * Returns an array of tokens this test wants to listen for.
24 *
25 * @return array
26 */
27 public function register()
28 {
29 return array(T_VARIABLE);
30
31 }//end register()
32
33
34 /**
35 * Processes this test, when one of its tokens is encountered.
36 *
37 * @param PHP_CodeSniffer_File $phpcsFile The current file being processed.
38 * @param int $stackPtr The position of the current token
39 * in the stack passed in $tokens.
40 *
41 * @return void
42 */
43 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
44 {
45 $string = $phpcsFile->getTokensAsString($stackPtr, 4);
46 if ($string === '$_SERVER["REMOTE_ADDR"]' || $string === '$_SERVER[\'REMOTE_ADDR\']') {
47 $error = 'Use the function ip_address() instead of $_SERVER[\'REMOTE_ADDR\']';
48 $phpcsFile->addError($error, $stackPtr, 'RemoteAddress');
49 }
50
51 }//end process()
52
53
54 }//end class