PHP Class PHP_CodeSniffer_Fixer, PHP_CodeSniffer

Provides helper functions that act upon a token array and modify the file content.
显示文件 Open project: squizlabs/php_codesniffer Class Usage Examples

Public Properties

Property Type Description
$enabled boolean Sniffs should check this value to ensure they are not doing extra processing to prepare for a fix when fixing is not required.
$loops integer The number of times we have looped over a file.

Public Methods

Method Description
addContent ( integer $stackPtr, string $content ) : boolean Adds content to the end of a token's current content.
addContentBefore ( integer $stackPtr, string $content ) : boolean Adds content to the start of a token's current content.
addNewline ( integer $stackPtr ) : boolean Adds a newline to end of a token's content.
addNewlineBefore ( integer $stackPtr ) : boolean Adds a newline to the start of a token's content.
beginChangeset ( ) : void Start recording actions for a changeset.
endChangeset ( ) : boolean Stop recording actions for a changeset, and apply logged changes.
fixFile ( ) : boolean Attempt to fix the file by processing it until no fixes are made.
generateDiff ( string $filePath = null, boolean $colors = true ) : string Generates a text diff of the original file and the new content.
getContents ( ) : string Get the current content of the file, as a string.
getFixCount ( ) : integer Get a count of fixes that have been performed on the file.
getTokenContent ( integer $stackPtr ) : string Get the current fixed content of a token.
replaceToken ( integer $stackPtr, string $content ) : boolean Replace the entire contents of a token.
revertToken ( integer $stackPtr ) : boolean Reverts the previous fix made to a token.
rollbackChangeset ( ) : void Stop recording actions for a changeset, and discard logged changes.
startFile ( PHP_CodeSniffer_File $phpcsFile ) : void Starts fixing a new file.
substrToken ( integer $stackPtr, integer $start, integer $length = null ) : boolean Replace the content of a token with a part of its current content.

Method Details

addContent() public method

Adds content to the end of a token's current content.
public addContent ( integer $stackPtr, string $content ) : boolean
$stackPtr integer The position of the token in the token stack.
$content string The content to add.
return boolean If the change was accepted.

addContentBefore() public method

Adds content to the start of a token's current content.
public addContentBefore ( integer $stackPtr, string $content ) : boolean
$stackPtr integer The position of the token in the token stack.
$content string The content to add.
return boolean If the change was accepted.

addNewline() public method

Adds a newline to end of a token's content.
public addNewline ( integer $stackPtr ) : boolean
$stackPtr integer The position of the token in the token stack.
return boolean If the change was accepted.

addNewlineBefore() public method

Adds a newline to the start of a token's content.
public addNewlineBefore ( integer $stackPtr ) : boolean
$stackPtr integer The position of the token in the token stack.
return boolean If the change was accepted.

beginChangeset() public method

Start recording actions for a changeset.
public beginChangeset ( ) : void
return void

endChangeset() public method

Stop recording actions for a changeset, and apply logged changes.
public endChangeset ( ) : boolean
return boolean

fixFile() public method

Attempt to fix the file by processing it until no fixes are made.
public fixFile ( ) : boolean
return boolean

generateDiff() public method

Generates a text diff of the original file and the new content.
public generateDiff ( string $filePath = null, boolean $colors = true ) : string
$filePath string Optional file path to diff the file against. If not specified, the original version of the file will be used.
$colors boolean Print colored output or not.
return string

getContents() public method

Get the current content of the file, as a string.
public getContents ( ) : string
return string

getFixCount() public method

This value is reset every time a new file is started, or an existing file is restarted.
public getFixCount ( ) : integer
return integer

getTokenContent() public method

This function takes changesets into account so should be used instead of directly accessing the token array.
public getTokenContent ( integer $stackPtr ) : string
$stackPtr integer The position of the token in the token stack.
return string

replaceToken() public method

Replace the entire contents of a token.
public replaceToken ( integer $stackPtr, string $content ) : boolean
$stackPtr integer The position of the token in the token stack.
$content string The new content of the token.
return boolean If the change was accepted.

revertToken() public method

Reverts the previous fix made to a token.
public revertToken ( integer $stackPtr ) : boolean
$stackPtr integer The position of the token in the token stack.
return boolean If a change was reverted.

rollbackChangeset() public method

Stop recording actions for a changeset, and discard logged changes.
public rollbackChangeset ( ) : void
return void

startFile() public method

Starts fixing a new file.
public startFile ( PHP_CodeSniffer_File $phpcsFile ) : void
$phpcsFile PHP_CodeSniffer_File The file being fixed.
return void

substrToken() public method

Replace the content of a token with a part of its current content.
public substrToken ( integer $stackPtr, integer $start, integer $length = null ) : boolean
$stackPtr integer The position of the token in the token stack.
$start integer The first character to keep.
$length integer The number of chacters to keep. If NULL, the content of the token from $start to the end of the content is kept.
return boolean If the change was accepted.

Property Details

$enabled public_oe property

Sniffs should check this value to ensure they are not doing extra processing to prepare for a fix when fixing is not required.
public bool $enabled
return boolean

$loops public_oe property

The number of times we have looped over a file.
public int $loops
return integer