wishthis/vendor/wp-coding-standards/wpcs/WordPress/Sniff.php
2023-09-20 13:52:46 +02:00

72 lines
1.8 KiB
PHP

<?php
/**
* Represents a PHP_CodeSniffer sniff for sniffing WordPress coding standards.
*
* @package WPCS\WordPressCodingStandards
* @link https://github.com/WordPress/WordPress-Coding-Standards
* @license https://opensource.org/licenses/MIT MIT
*/
namespace WordPressCS\WordPress;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff as PHPCS_Sniff;
/**
* Represents a PHP_CodeSniffer sniff for sniffing WordPress coding standards.
*
* Provides a bootstrap for the sniffs, to reduce code duplication.
*
* @since 0.4.0
*/
abstract class Sniff implements PHPCS_Sniff {
/**
* The current file being sniffed.
*
* @since 0.4.0
*
* @var \PHP_CodeSniffer\Files\File
*/
protected $phpcsFile;
/**
* The list of tokens in the current file being sniffed.
*
* @since 0.4.0
*
* @var array
*/
protected $tokens;
/**
* Set sniff properties and hand off to child class for processing of the token.
*
* @since 0.11.0
*
* @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 int|void Integer stack pointer to skip forward or void to continue
* normal file processing.
*/
public function process( File $phpcsFile, $stackPtr ) {
$this->phpcsFile = $phpcsFile;
$this->tokens = $phpcsFile->getTokens();
return $this->process_token( $stackPtr );
}
/**
* Processes a sniff when one of its tokens is encountered.
*
* @since 0.11.0
*
* @param int $stackPtr The position of the current token in the stack.
*
* @return int|void Integer stack pointer to skip forward or void to continue
* normal file processing.
*/
abstract public function process_token( $stackPtr );
}