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

Breadcrumb

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

class DeprecatedFunctionsSniff

Hierarchy

  • class \PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\ForbiddenFunctionsSniff implements \PHP_CodeSniffer\Sniffs\Sniff
    • class \PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\DeprecatedFunctionsSniff extends \PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\ForbiddenFunctionsSniff

Expanded class hierarchy of DeprecatedFunctionsSniff

File

vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/PHP/DeprecatedFunctionsSniff.php, line 15

Namespace

PHP_CodeSniffer\Standards\Generic\Sniffs\PHP
View source
class DeprecatedFunctionsSniff extends ForbiddenFunctionsSniff {
    
    /**
     * A list of forbidden functions with their alternatives.
     *
     * The value is NULL if no alternative exists. IE, the
     * function should just not be used.
     *
     * @var array<string, string|null>
     */
    public $forbiddenFunctions = [];
    
    /**
     * Constructor.
     *
     * Uses the Reflection API to get a list of deprecated functions.
     */
    public function __construct() {
        $functions = get_defined_functions();
        foreach ($functions['internal'] as $functionName) {
            $function = new ReflectionFunction($functionName);
            if ($function->isDeprecated() === true) {
                $this->forbiddenFunctions[$functionName] = null;
            }
        }
    }
    
    //end __construct()
    
    /**
     * Generates the error or warning for this sniff.
     *
     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
     * @param int                         $stackPtr  The position of the forbidden function
     *                                               in the token array.
     * @param string                      $function  The name of the forbidden function.
     * @param string                      $pattern   The pattern used for the match.
     *
     * @return void
     */
    protected function addError($phpcsFile, $stackPtr, $function, $pattern = null) {
        $data = [
            $function,
        ];
        $error = 'Function %s() has been deprecated';
        $type = 'Deprecated';
        if ($this->error === true) {
            $phpcsFile->addError($error, $stackPtr, $type, $data);
        }
        else {
            $phpcsFile->addWarning($error, $stackPtr, $type, $data);
        }
    }
    
    //end addError()

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
DeprecatedFunctionsSniff::$forbiddenFunctions public property A list of forbidden functions with their alternatives. Overrides ForbiddenFunctionsSniff::$forbiddenFunctions
DeprecatedFunctionsSniff::addError protected function Generates the error or warning for this sniff. Overrides ForbiddenFunctionsSniff::addError
DeprecatedFunctionsSniff::__construct public function Constructor.
ForbiddenFunctionsSniff::$error public property If true, an error will be thrown; otherwise a warning. 2
ForbiddenFunctionsSniff::$forbiddenFunctionNames protected property A cache of forbidden function names, for faster lookups.
ForbiddenFunctionsSniff::$patternMatch protected property If true, forbidden functions will be considered regular expressions.
ForbiddenFunctionsSniff::process public function Processes this test, when one of its tokens is encountered. Overrides Sniff::process
ForbiddenFunctionsSniff::register public function Returns an array of tokens this test wants to listen for. Overrides Sniff::register
RSS feed
Powered by Drupal