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

Breadcrumb

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

class MethodScopeSniff

Same name in this branch
  1. 11.1.x vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Scope/MethodScopeSniff.php \Drupal\Sniffs\Scope\MethodScopeSniff

Hierarchy

  • class \PHP_CodeSniffer\Sniffs\AbstractScopeSniff implements \PHP_CodeSniffer\Sniffs\Sniff
    • class \PHP_CodeSniffer\Standards\Squiz\Sniffs\Scope\MethodScopeSniff extends \PHP_CodeSniffer\Sniffs\AbstractScopeSniff

Expanded class hierarchy of MethodScopeSniff

File

vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Scope/MethodScopeSniff.php, line 16

Namespace

PHP_CodeSniffer\Standards\Squiz\Sniffs\Scope
View source
class MethodScopeSniff extends AbstractScopeSniff {
    
    /**
     * Constructs a Squiz_Sniffs_Scope_MethodScopeSniff.
     */
    public function __construct() {
        parent::__construct(Tokens::$ooScopeTokens, [
            T_FUNCTION,
        ]);
    }
    
    //end __construct()
    
    /**
     * Processes the function tokens within the class.
     *
     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found.
     * @param int                         $stackPtr  The position where the token was found.
     * @param int                         $currScope The current scope opener token.
     *
     * @return void
     */
    protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope) {
        $tokens = $phpcsFile->getTokens();
        // Determine if this is a function which needs to be examined.
        $conditions = $tokens[$stackPtr]['conditions'];
        end($conditions);
        $deepestScope = key($conditions);
        if ($deepestScope !== $currScope) {
            return;
        }
        $methodName = $phpcsFile->getDeclarationName($stackPtr);
        if ($methodName === null) {
            // Ignore closures.
            return;
        }
        $properties = $phpcsFile->getMethodProperties($stackPtr);
        if ($properties['scope_specified'] === false) {
            $error = 'Visibility must be declared on method "%s"';
            $data = [
                $methodName,
            ];
            $phpcsFile->addError($error, $stackPtr, 'Missing', $data);
        }
    }
    
    //end processTokenWithinScope()
    
    /**
     * Processes a token that is found within the scope that this test is
     * listening to.
     *
     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found.
     * @param int                         $stackPtr  The position in the stack where this
     *                                               token was found.
     *
     * @return void
     */
    protected function processTokenOutsideScope(File $phpcsFile, $stackPtr) {
    }
    
    //end processTokenOutsideScope()

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
AbstractScopeSniff::$listenOutside private property True if this test should fire on tokens outside of the scope.
AbstractScopeSniff::$scopeTokens private property The type of scope opener tokens that this test wishes to listen to.
AbstractScopeSniff::$tokens private property The token types that this test wishes to listen to within the scope.
AbstractScopeSniff::process final public function Processes the tokens that this test is listening for. Overrides Sniff::process
AbstractScopeSniff::register final public function The method that is called to register the tokens this test wishes to
listen to.
Overrides Sniff::register
MethodScopeSniff::processTokenOutsideScope protected function Processes a token that is found within the scope that this test is
listening to.
Overrides AbstractScopeSniff::processTokenOutsideScope
MethodScopeSniff::processTokenWithinScope protected function Processes the function tokens within the class. Overrides AbstractScopeSniff::processTokenWithinScope
MethodScopeSniff::__construct public function Constructs a Squiz_Sniffs_Scope_MethodScopeSniff. Overrides AbstractScopeSniff::__construct
RSS feed
Powered by Drupal