Ruleset
in package
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.
- $config : Config
- The config data for the run.
- $deprecatedSniffs : array<string, string>
- An array of the names of sniffs which have been marked as deprecated.
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.
- 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, 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
= []
$config
The config data for the run.
private
Config
$config
= null
$deprecatedSniffs
An array of the names of sniffs which have been marked as deprecated.
private
array<string, string>
$deprecatedSniffs
= []
The key is the sniff code and the value is the fully qualified name of the sniff class.
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 $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>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
Tags
expandRulesetReference()
Expands a ruleset reference into a list of sniff files.
private
expandRulesetReference(string $ref, string $rulesetDir[, int $depth = 0 ]) : 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 = 0
-
How many nested processing steps we are in. This is only used for debug output.
Tags
Return values
array<string|int, mixed>expandSniffDirectory()
Expands a directory into a list of sniff files within.
private
expandSniffDirectory(string $directory[, int $depth = 0 ]) : array<string|int, mixed>
Parameters
- $directory : string
-
The path to a directory.
- $depth : int = 0
-
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 = 0 ]) : 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 = 0
-
How many nested processing steps we are in. This is only used for debug output.
Tags
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.