You are here

abstract class FunctionDefinition in Coder 8.3.x

Same name and namespace in other branches
  1. 8.3 coder_sniffer/Drupal/Sniffs/Semantics/FunctionDefinition.php \Drupal\Sniffs\Semantics\FunctionDefinition
  2. 8.2 coder_sniffer/Drupal/Sniffs/Semantics/FunctionDefinition.php \Drupal\Sniffs\Semantics\FunctionDefinition

Helper class to sniff for function definitions.

@category PHP @package PHP_CodeSniffer @link http://pear.php.net/package/PHP_CodeSniffer

Hierarchy

  • class \Drupal\Sniffs\Semantics\FunctionDefinition implements \PHP_CodeSniffer\Sniffs\Sniff

Expanded class hierarchy of FunctionDefinition

5 files declare their use of FunctionDefinition
AccessAdminPagesSniff.php in coder_sniffer/DrupalPractice/Sniffs/General/AccessAdminPagesSniff.php
AccessHookMenuSniff.php in coder_sniffer/DrupalPractice/Sniffs/FunctionDefinitions/AccessHookMenuSniff.php
FormAlterDocSniff.php in coder_sniffer/DrupalPractice/Sniffs/FunctionDefinitions/FormAlterDocSniff.php
HookInitCssSniff.php in coder_sniffer/DrupalPractice/Sniffs/FunctionDefinitions/HookInitCssSniff.php
InstallTSniff.php in coder_sniffer/DrupalPractice/Sniffs/FunctionDefinitions/InstallTSniff.php

File

coder_sniffer/Drupal/Sniffs/Semantics/FunctionDefinition.php, line 23

Namespace

Drupal\Sniffs\Semantics
View source
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,
    ];
  }

  //end register()

  /**
   * 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::$emptyTokens, $stackPtr - 1, null, true);
    if ($tokens[$functionPtr]['code'] === T_FUNCTION) {
      $this
        ->processFunction($phpcsFile, $stackPtr, $functionPtr);
    }
  }

  //end process()

  /**
   * 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
   */
  public abstract function processFunction(File $phpcsFile, $stackPtr, $functionPtr);

}

Members

Namesort descending Modifiers Type Description Overrides
FunctionDefinition::process public function Processes this test, when one of its tokens is encountered.
FunctionDefinition::processFunction abstract public function Process this function definition. 9
FunctionDefinition::register public function Returns an array of tokens this test wants to listen for.