PHP Класс PHP_CodeSniffer_Fixer, PHP_CodeSniffer

Provides helper functions that act upon a token array and modify the file content.
Автор: Greg Sherwood ([email protected])
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$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.

Открытые методы

Метод Описание
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.

Описание методов

addContent() публичный Метод

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.
Результат boolean If the change was accepted.

addContentBefore() публичный Метод

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.
Результат boolean If the change was accepted.

addNewline() публичный Метод

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.
Результат boolean If the change was accepted.

addNewlineBefore() публичный Метод

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.
Результат boolean If the change was accepted.

beginChangeset() публичный Метод

Start recording actions for a changeset.
public beginChangeset ( ) : void
Результат void

endChangeset() публичный Метод

Stop recording actions for a changeset, and apply logged changes.
public endChangeset ( ) : boolean
Результат boolean

fixFile() публичный Метод

Attempt to fix the file by processing it until no fixes are made.
public fixFile ( ) : boolean
Результат boolean

generateDiff() публичный Метод

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.
Результат string

getContents() публичный Метод

Get the current content of the file, as a string.
public getContents ( ) : string
Результат string

getFixCount() публичный Метод

This value is reset every time a new file is started, or an existing file is restarted.
public getFixCount ( ) : integer
Результат integer

getTokenContent() публичный Метод

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.
Результат string

replaceToken() публичный Метод

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.
Результат boolean If the change was accepted.

revertToken() публичный Метод

Reverts the previous fix made to a token.
public revertToken ( integer $stackPtr ) : boolean
$stackPtr integer The position of the token in the token stack.
Результат boolean If a change was reverted.

rollbackChangeset() публичный Метод

Stop recording actions for a changeset, and discard logged changes.
public rollbackChangeset ( ) : void
Результат void

startFile() публичный Метод

Starts fixing a new file.
public startFile ( PHP_CodeSniffer_File $phpcsFile ) : void
$phpcsFile PHP_CodeSniffer_File The file being fixed.
Результат void

substrToken() публичный Метод

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.
Результат boolean If the change was accepted.

Описание свойств

$enabled публичное свойство

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
Результат boolean

$loops публичное свойство

The number of times we have looped over a file.
public int $loops
Результат integer