PHP Class Generic_Sniffs_PHP_DisallowAlternativePHPTagsSniff, PHP_CodeSniffer

Verifies that no alternative PHP tags are used. If alternative PHP open tags are found, this sniff can fix both the open and close tags.
Author: Greg Sherwood ([email protected])
Author: Marc McIntyre ([email protected])
Inheritance: implements PHP_CodeSniffer_Sniff
ファイルを表示 Open project: squizlabs/php_codesniffer

Public Methods

Method Description
process ( PHP_CodeSniffer_File $phpcsFile, integer $stackPtr ) : void Processes this test, when one of its tokens is encountered.
register ( ) : array Returns an array of tokens this test wants to listen for.

Protected Methods

Method Description
addChangeset ( PHP_CodeSniffer_File $phpcsFile, array $tokens, integer $open_tag_pointer, integer $close_tag_pointer, boolean $echo = false ) : void Add a changeset to replace the alternative PHP tags.
findClosingTag ( PHP_CodeSniffer_File $phpcsFile, array $tokens, integer $stackPtr, string $content ) : integer | false Try and find a matching PHP closing tag.
getSnippet ( string $content, string $start_at = '', integer $length = 40 ) : string Get a snippet from a HTML token.

Method Details

addChangeset() protected method

Add a changeset to replace the alternative PHP tags.
protected addChangeset ( PHP_CodeSniffer_File $phpcsFile, array $tokens, integer $open_tag_pointer, integer $close_tag_pointer, boolean $echo = false ) : void
$phpcsFile PHP_CodeSniffer_File The file being scanned.
$tokens array The token stack.
$open_tag_pointer integer Stack pointer to the PHP open tag.
$close_tag_pointer integer Stack pointer to the PHP close tag.
$echo boolean Whether to add 'echo' or not.
return void

findClosingTag() protected method

Try and find a matching PHP closing tag.
protected findClosingTag ( PHP_CodeSniffer_File $phpcsFile, array $tokens, integer $stackPtr, string $content ) : integer | false
$phpcsFile PHP_CodeSniffer_File The file being scanned.
$tokens array The token stack.
$stackPtr integer The position of the current token in the stack passed in $tokens.
$content string The expected content of the closing tag to match the opener.
return integer | false Pointer to the position in the stack for the closing tag or false if not found.

getSnippet() protected method

Get a snippet from a HTML token.
protected getSnippet ( string $content, string $start_at = '', integer $length = 40 ) : string
$content string The content of the HTML token.
$start_at string Partial string to use as a starting point for the snippet.
$length integer The target length of the snippet to get. Defaults to 40.
return string

process() public method

Processes this test, when one of its tokens is encountered.
public process ( PHP_CodeSniffer_File $phpcsFile, integer $stackPtr ) : void
$phpcsFile PHP_CodeSniffer_File The file being scanned.
$stackPtr integer The position of the current token in the stack passed in $tokens.
return void

register() public method

Returns an array of tokens this test wants to listen for.
public register ( ) : array
return array