RulesetDouble
extends Ruleset
in package
Ruleset class for use in the tests.
The PHP_CodeSniffer Ruleset will throw an error when no (valid) sniffs are registered, but for utility method tests, we're not concerned about that.
This ruleset double will catch this error and discard it.
Tags
Table of Contents
Properties
- $ignorePatterns : array<string, array<string|int, mixed>>
- 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, array<string, array<string, mixed>>>
- 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.
Methods
- __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.
- hasSniffDeprecations() : bool
- Checks whether any deprecated sniffs were registered via the ruleset.
- 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.
- showSniffDeprecations() : void
- Prints an information block about deprecated sniffs being used.
Properties
$ignorePatterns
A list of regular expressions used to ignore specific sniffs for files and folders.
public
array<string, array<string|int, mixed>>
$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, array<string, array<string, mixed>>>
$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
= []
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
explain()
Prints a report showing the sniffs contained in a standard.
public
explain() : void
getIgnorePatterns()
Gets the array of ignore patterns.
public
getIgnorePatterns([string|null $listener = null ]) : array<string|int, mixed>
Optionally takes a listener to get ignore patterns specified for that sniff only.
Parameters
- $listener : string|null = 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|null $listener = null ]) : array<string|int, mixed>
Optionally takes a listener to get include patterns specified for that sniff only.
Parameters
- $listener : string|null = null
-
The listener to get patterns for. If NULL, all patterns are returned.
Return values
array<string|int, mixed>hasSniffDeprecations()
Checks whether any deprecated sniffs were registered via the ruleset.
public
hasSniffDeprecations() : bool
Return values
boolpopulateTokenListeners()
Populates the array of PHP_CodeSniffer_Sniff objects for this file.
public
populateTokenListeners() : void
Tags
processRuleset()
Processes a single ruleset and returns a list of the sniffs it represents.
public
processRuleset(string $rulesetPath[, int $depth = 0 ]) : 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 = 0
-
How many nested processing steps we are in. This is only used for debug output.
Tags
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.
setSniffProperty()
Set a single property for a sniff.
public
setSniffProperty(string $sniffClass, string $name, array<string|int, mixed> $settings) : void
Parameters
- $sniffClass : string
-
The class name of the sniff.
- $name : string
-
The name of the property to change.
- $settings : array<string|int, mixed>
-
Array with the new value of the property and the scope of the property being set.
Tags
showSniffDeprecations()
Prints an information block about deprecated sniffs being used.
public
showSniffDeprecations() : void