comparison vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Semantics/RemoteAddressSniff.php @ 17:129ea1e6d783

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