coder-8.x-3.x-dev/coder_sniffer/Drupal/Sniffs/Semantics/FunctionDefinition.php

coder_sniffer/Drupal/Sniffs/Semantics/FunctionDefinition.php
<?php
/**
 * \Drupal\Sniffs\Semantics\FunctionDefinition.
 *
 * @category PHP
 * @package  PHP_CodeSniffer
 * @link     http://pear.php.net/package/PHP_CodeSniffer
 */

namespace Drupal\Sniffs\Semantics;

use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Util\Tokens;

/**
 * Helper class to sniff for function definitions.
 *
 * @category PHP
 * @package  PHP_CodeSniffer
 * @link     http://pear.php.net/package/PHP_CodeSniffer
 */
abstract class FunctionDefinition implements Sniff
{


    /**
     * Returns an array of tokens this test wants to listen for.
     *
     * @return array<int|string>
     */
    public function register()
    {
        return [T_STRING];
    }


    /**
     * Processes this test, when one of its tokens is encountered.
     *
     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
     * @param int                         $stackPtr  The position of the current token
     *                                               in the stack passed in $tokens.
     *
     * @return void
     */
    public function process(File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();
        // Check if this is a function definition.
        $functionPtr = $phpcsFile->findPrevious(
            Tokens::EMPTY_TOKENS,
            ($stackPtr - 1),
            null,
            true
        );
        if ($tokens[$functionPtr]['code'] === T_FUNCTION) {
            $this->processFunction($phpcsFile, $stackPtr, $functionPtr);
        }
    }


    /**
     * Process this function definition.
     *
     * @param \PHP_CodeSniffer\Files\File $phpcsFile   The file being scanned.
     * @param int                         $stackPtr    The position of the function name in the stack.
     *                                                 name in the stack.
     * @param int                         $functionPtr The position of the function keyword in the stack.
     *                                                 keyword in the stack.
     *
     * @return void
     */
    abstract public function processFunction(File $phpcsFile, $stackPtr, $functionPtr);
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc