Documentation

Ruleset
in package

Table of Contents

$ignorePatterns  : array<string, string>
A list of regular expressions used to ignore specific sniffs for files and folders.
$includePatterns  : array<string, array<string, string>>
A list of regular expressions used to include specific sniffs for files and folders.
$name  : string
The name of the coding standard being used.
$paths  : array<string|int, string>
A list of file paths for the ruleset files being used.
$ruleset  : array<string, mixed>
An array of rules from the ruleset.xml file.
$sniffCodes  : array<string, string>
A mapping of sniff codes to fully qualified class names.
$sniffs  : array<string, Sniff>
An array of sniff objects that are being used to check files.
$tokenListeners  : array<int, Sniff>
An array of token types and the sniffs that are listening for them.
$rulesetDirs  : array<string|int, string>
The directories that the processed rulesets are in.
$config  : Config
The config data for the run.
__construct()  : void
Initialise the ruleset that the run will use.
explain()  : void
Prints a report showing the sniffs contained in a standard.
getIgnorePatterns()  : array<string|int, mixed>
Gets the array of ignore patterns.
getIncludePatterns()  : array<string|int, mixed>
Gets the array of include patterns.
populateTokenListeners()  : void
Populates the array of PHP_CodeSniffer_Sniff objects for this file.
processRuleset()  : array<string|int, string>
Processes a single ruleset and returns a list of the sniffs it represents.
registerSniffs()  : void
Loads and stores sniffs objects used for sniffing files.
setSniffProperty()  : void
Set a single property for a sniff.
expandRulesetReference()  : array<string|int, mixed>
Expands a ruleset reference into a list of sniff files.
expandSniffDirectory()  : array<string|int, mixed>
Expands a directory into a list of sniff files within.
processRule()  : void
Processes a rule from a ruleset XML file, overriding built-in defaults.
shouldProcessElement()  : bool
Determine if an element should be processed or ignored.

Properties

$ignorePatterns

A list of regular expressions used to ignore specific sniffs for files and folders.

public array<string, string> $ignorePatterns = []

Is also used to set global exclude patterns. The key is the regular expression and the value is the type of ignore pattern (absolute or relative).

$includePatterns

A list of regular expressions used to include specific sniffs for files and folders.

public array<string, array<string, string>> $includePatterns = []

The key is the sniff code and the value is an array with the key being a regular expression and the value is the type of ignore pattern (absolute or relative).

$name

The name of the coding standard being used.

public string $name = ''

If a top-level standard includes other standards, or sniffs from other standards, only the name of the top-level standard will be stored in here.

If multiple top-level standards are being loaded into a single ruleset object, this will store a comma separated list of the top-level standard names.

$paths

A list of file paths for the ruleset files being used.

public array<string|int, string> $paths = []

$ruleset

An array of rules from the ruleset.xml file.

public array<string, mixed> $ruleset = []

It may be empty, indicating that the ruleset does not override any of the default sniff settings.

$sniffCodes

A mapping of sniff codes to fully qualified class names.

public array<string, string> $sniffCodes = []

The key is the sniff code and the value is the fully qualified name of the sniff class.

$sniffs

An array of sniff objects that are being used to check files.

public array<string, Sniff> $sniffs = []

The key is the fully qualified name of the sniff class and the value is the sniff object.

$tokenListeners

An array of token types and the sniffs that are listening for them.

public array<int, Sniff> $tokenListeners = []

The key is the token name being listened for and the value is the sniff object.

$rulesetDirs

The directories that the processed rulesets are in.

protected array<string|int, string> $rulesetDirs = []

$config

The config data for the run.

private Config $config = null

Methods

__construct()

Initialise the ruleset that the run will use.

public __construct(Config $config) : void
Parameters
$config : Config

The config data for the run.

Tags
throws
RuntimeException

If no sniffs were registered.

Return values
void

explain()

Prints a report showing the sniffs contained in a standard.

public explain() : void
Return values
void

getIgnorePatterns()

Gets the array of ignore patterns.

public getIgnorePatterns([string $listener = null ]) : array<string|int, mixed>

Optionally takes a listener to get ignore patterns specified for that sniff only.

Parameters
$listener : string = null

The listener to get patterns for. If NULL, all patterns are returned.

Return values
array<string|int, mixed>

getIncludePatterns()

Gets the array of include patterns.

public getIncludePatterns([string $listener = null ]) : array<string|int, mixed>

Optionally takes a listener to get include patterns specified for that sniff only.

Parameters
$listener : string = null

The listener to get patterns for. If NULL, all patterns are returned.

Return values
array<string|int, mixed>

populateTokenListeners()

Populates the array of PHP_CodeSniffer_Sniff objects for this file.

public populateTokenListeners() : void
Tags
throws
RuntimeException

If sniff registration fails.

Return values
void

processRuleset()

Processes a single ruleset and returns a list of the sniffs it represents.

public processRuleset(string $rulesetPath, int $depth) : array<string|int, string>

Rules founds within the ruleset are processed immediately, but sniff classes are not registered by this method.

Parameters
$rulesetPath : string

The path to a ruleset XML file.

$depth : int

How many nested processing steps we are in. This is only used for debug output.

Tags
throws
RuntimeException
  • If the ruleset path is invalid.
  • If a specified autoload file could not be found.
Return values
array<string|int, string>

registerSniffs()

Loads and stores sniffs objects used for sniffing files.

public registerSniffs(array<string|int, mixed> $files, array<string|int, mixed> $restrictions, array<string|int, mixed> $exclusions) : void
Parameters
$files : array<string|int, mixed>

Paths to the sniff files to register.

$restrictions : array<string|int, mixed>

The sniff class names to restrict the allowed listeners to.

$exclusions : array<string|int, mixed>

The sniff class names to exclude from the listeners list.

Return values
void

setSniffProperty()

Set a single property for a sniff.

public setSniffProperty(string $sniffClass, string $name, string $value) : void
Parameters
$sniffClass : string

The class name of the sniff.

$name : string

The name of the property to change.

$value : string

The new value of the property.

Return values
void

expandRulesetReference()

Expands a ruleset reference into a list of sniff files.

private expandRulesetReference(string $ref, string $rulesetDir, int $depth) : array<string|int, mixed>
Parameters
$ref : string

The reference from the ruleset XML file.

$rulesetDir : string

The directory of the ruleset XML file, used to evaluate relative paths.

$depth : int

How many nested processing steps we are in. This is only used for debug output.

Tags
throws
RuntimeException

If the reference is invalid.

Return values
array<string|int, mixed>

expandSniffDirectory()

Expands a directory into a list of sniff files within.

private expandSniffDirectory(string $directory, int $depth) : array<string|int, mixed>
Parameters
$directory : string

The path to a directory.

$depth : int

How many nested processing steps we are in. This is only used for debug output.

Return values
array<string|int, mixed>

processRule()

Processes a rule from a ruleset XML file, overriding built-in defaults.

private processRule(SimpleXMLElement $rule, array<string|int, string> $newSniffs, int $depth) : void
Parameters
$rule : SimpleXMLElement

The rule object from a ruleset XML file.

$newSniffs : array<string|int, string>

An array of sniffs that got included by this rule.

$depth : int

How many nested processing steps we are in. This is only used for debug output.

Tags
throws
RuntimeException

If rule settings are invalid.

Return values
void

shouldProcessElement()

Determine if an element should be processed or ignored.

private shouldProcessElement(SimpleXMLElement $element) : bool
Parameters
$element : SimpleXMLElement

An object from a ruleset XML file.

Return values
bool

Search results