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.
- $cliSettingsApplied : array<string, int>
- The `<arg>` directives which have been applied.
- $config : Config
- The config data for the run.
- $configDirectivesApplied : array<string, int>
- The `<config>` directives which have been applied.
- $deprecatedSniffs : array<string, string>
- An array of the names of sniffs which have been marked as deprecated.
- $msgCache : MessageCollector
- Message collector object.
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.
- displayCachedMessages() : void
- Print any notices encountered while processing the ruleset(s).
- 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.
- getRealPropertyValue() : mixed
- Transform a property value received via a ruleset or inline annotation to a typed value.
- 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
= []
$cliSettingsApplied
The `<arg>` directives which have been applied.
private
array<string, int>
$cliSettingsApplied
= []
Key is the name of the setting. Value is the ruleset depth at which this setting was applied (if not overruled from the CLI).
$config
The config data for the run.
private
Config
$config
= null
$configDirectivesApplied
The `<config>` directives which have been applied.
private
array<string, int>
$configDirectivesApplied
= []
Key is the name of the config. Value is the ruleset depth at which this config was applied (if not overruled from the CLI).
$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.
$msgCache
Message collector object.
private
MessageCollector
$msgCache
User-facing messages should be collected via this object for display once the ruleset processing has finished.
The following type of errors should NOT be collected, but should still throw their own RuntimeException:
- Errors which could cause other (uncollectable) errors further into the ruleset processing, like a missing autoload file.
- Errors which are directly aimed at and only intended for sniff developers or integrators (in contrast to ruleset maintainers or end-users).
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. May optionally include an
extendkey to indicate a pre-existing array value should be extended.
Tags
showSniffDeprecations()
Prints an information block about deprecated sniffs being used.
public
showSniffDeprecations() : void
Tags
displayCachedMessages()
Print any notices encountered while processing the ruleset(s).
private
displayCachedMessages() : void
Note: these messages aren't shown at the time they are encountered to avoid "one error hiding behind another". This way the (end-)user gets to see all of them in one go.
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>getRealPropertyValue()
Transform a property value received via a ruleset or inline annotation to a typed value.
private
getRealPropertyValue(string|array<int|string, string> $value) : mixed
Parameters
- $value : string|array<int|string, string>
-
The current property value.
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.