Documentation

Fixer
in package

Table of Contents

$enabled  : bool
Is the fixer enabled and fixing a file?
$loops  : int
The number of times we have looped over a file.
$changeset  : array<string|int, mixed>
A list of tokens that have been fixed during a changeset.
$currentFile  : File
The file being fixed.
$fixedTokens  : array<string|int, int>
A list of tokens that have already been fixed.
$inChangeset  : bool
Is there an open changeset.
$inConflict  : bool
Is the current fixing loop in conflict?
$numFixes  : int
The number of fixes that have been performed.
$oldTokenValues  : array<int, string>
The last value of each fixed token.
$tokens  : array<int, string>
The list of tokens that make up the file contents.
addContent()  : bool
Adds content to the end of a token's current content.
addContentBefore()  : bool
Adds content to the start of a token's current content.
addNewline()  : bool
Adds a newline to end of a token's content.
addNewlineBefore()  : bool
Adds a newline to the start of a token's content.
beginChangeset()  : void
Start recording actions for a changeset.
changeCodeBlockIndent()  : void
Adjust the indent of a code block.
endChangeset()  : bool
Stop recording actions for a changeset, and apply logged changes.
fixFile()  : bool
Attempt to fix the file by processing it until no fixes are made.
generateDiff()  : 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()  : int
Get a count of fixes that have been performed on the file.
getTokenContent()  : string
Get the current fixed content of a token.
replaceToken()  : bool
Replace the entire contents of a token.
revertToken()  : bool
Reverts the previous fix made to a token.
rollbackChangeset()  : void
Stop recording actions for a changeset, and discard logged changes.
startFile()  : void
Starts fixing a new file.
substrToken()  : bool
Replace the content of a token with a part of its current content.

Properties

$enabled

Is the fixer enabled and fixing a file?

public bool $enabled = false

Sniffs should check this value to ensure they are not doing extra processing to prepare for a fix when fixing is not required.

$loops

The number of times we have looped over a file.

public int $loops = 0

$changeset

A list of tokens that have been fixed during a changeset.

private array<string|int, mixed> $changeset = []

All changes in changeset must be able to be applied, or else the entire changeset is rejected.

$currentFile

The file being fixed.

private File $currentFile = null

$fixedTokens

A list of tokens that have already been fixed.

private array<string|int, int> $fixedTokens = []

We don't allow the same token to be fixed more than once each time through a file as this can easily cause conflicts between sniffs.

$inChangeset

Is there an open changeset.

private bool $inChangeset = false

$inConflict

Is the current fixing loop in conflict?

private bool $inConflict = false

$numFixes

The number of fixes that have been performed.

private int $numFixes = 0

$oldTokenValues

The last value of each fixed token.

private array<int, string> $oldTokenValues = []

If a token is being "fixed" back to its last value, the fix is probably conflicting with another.

$tokens

The list of tokens that make up the file contents.

private array<int, string> $tokens = []

This is a simplified list which just contains the token content and nothing else. This is the array that is updated as fixes are made, not the file's token array. Imploding this array will give you the file content back.

Methods

addContent()

Adds content to the end of a token's current content.

public addContent(int $stackPtr, string $content) : bool
Parameters
$stackPtr : int

The position of the token in the token stack.

$content : string

The content to add.

Return values
bool

If the change was accepted.

addContentBefore()

Adds content to the start of a token's current content.

public addContentBefore(int $stackPtr, string $content) : bool
Parameters
$stackPtr : int

The position of the token in the token stack.

$content : string

The content to add.

Return values
bool

If the change was accepted.

addNewline()

Adds a newline to end of a token's content.

public addNewline(int $stackPtr) : bool
Parameters
$stackPtr : int

The position of the token in the token stack.

Return values
bool

If the change was accepted.

addNewlineBefore()

Adds a newline to the start of a token's content.

public addNewlineBefore(int $stackPtr) : bool
Parameters
$stackPtr : int

The position of the token in the token stack.

Return values
bool

If the change was accepted.

beginChangeset()

Start recording actions for a changeset.

public beginChangeset() : void
Return values
void

changeCodeBlockIndent()

Adjust the indent of a code block.

public changeCodeBlockIndent(int $start, int $end, int $change) : void
Parameters
$start : int

The position of the token in the token stack to start adjusting the indent from.

$end : int

The position of the token in the token stack to end adjusting the indent.

$change : int

The number of spaces to adjust the indent by (positive or negative).

Return values
void

endChangeset()

Stop recording actions for a changeset, and apply logged changes.

public endChangeset() : bool
Return values
bool

fixFile()

Attempt to fix the file by processing it until no fixes are made.

public fixFile() : bool
Return values
bool

generateDiff()

Generates a text diff of the original file and the new content.

public generateDiff([string $filePath = null ][, bool $colors = true ]) : string
Parameters
$filePath : string = null

Optional file path to diff the file against. If not specified, the original version of the file will be used.

$colors : bool = true

Print coloured output or not.

Return values
string

getContents()

Get the current content of the file, as a string.

public getContents() : string
Return values
string

getFixCount()

Get a count of fixes that have been performed on the file.

public getFixCount() : int

This value is reset every time a new file is started, or an existing file is restarted.

Return values
int

getTokenContent()

Get the current fixed content of a token.

public getTokenContent(int $stackPtr) : string

This function takes changesets into account so should be used instead of directly accessing the token array.

Parameters
$stackPtr : int

The position of the token in the token stack.

Return values
string

replaceToken()

Replace the entire contents of a token.

public replaceToken(int $stackPtr, string $content) : bool
Parameters
$stackPtr : int

The position of the token in the token stack.

$content : string

The new content of the token.

Return values
bool

If the change was accepted.

revertToken()

Reverts the previous fix made to a token.

public revertToken(int $stackPtr) : bool
Parameters
$stackPtr : int

The position of the token in the token stack.

Return values
bool

If a change was reverted.

rollbackChangeset()

Stop recording actions for a changeset, and discard logged changes.

public rollbackChangeset() : void
Return values
void

startFile()

Starts fixing a new file.

public startFile(File $phpcsFile) : void
Parameters
$phpcsFile : File

The file being fixed.

Return values
void

substrToken()

Replace the content of a token with a part of its current content.

public substrToken(int $stackPtr, int $start[, int $length = null ]) : bool
Parameters
$stackPtr : int

The position of the token in the token stack.

$start : int

The first character to keep.

$length : int = null

The number of characters to keep. If NULL, the content of the token from $start to the end of the content is kept.

Return values
bool

If the change was accepted.

Search results