Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. RemoteAddressSniff.php

class RemoteAddressSniff

Make sure that ip_address() or Drupal::request()->getClientIp() 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

vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Semantics/RemoteAddressSniff.php, line 23

Namespace

Drupal\Sniffs\Semantics
View source
class RemoteAddressSniff implements Sniff {
    
    /**
     * Returns an array of tokens this test wants to listen for.
     *
     * @return array<int|string>
     */
    public function register() {
        return [
            T_VARIABLE,
        ];
    }
    
    //end register()
    
    /**
     * Processes this test, when one of its tokens is encountered.
     *
     * @param \PHP_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);
        $startOfStatement = $phpcsFile->findStartOfStatement($stackPtr);
        if (($string === '$_SERVER["REMOTE_ADDR"]' || $string === '$_SERVER[\'REMOTE_ADDR\']') && $stackPtr !== $startOfStatement) {
            $error = 'Use ip_address() or Drupal::request()->getClientIp() instead of $_SERVER[\'REMOTE_ADDR\']';
            $phpcsFile->addError($error, $stackPtr, 'RemoteAddress');
        }
    }
    
    //end process()

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
RemoteAddressSniff::process public function Processes this test, when one of its tokens is encountered. Overrides Sniff::process
RemoteAddressSniff::register public function Returns an array of tokens this test wants to listen for. Overrides Sniff::register
RSS feed
Powered by Drupal