ConstructorArgumentMatcher extends AbstractCoreMatcher
Finds invocations to class constructors and the amount of passed arguments.
This matcher supports direct new MyClass(123)
invocations as well as delegated
calls to GeneralUtility::makeInstance(MyClass::class, 123)
using GeneratorClassResolver
.
These configuration property names are handled independently:
- numberOfMandatoryArguments
- maximumNumberOfArguments
- unusedArgumentNumbers
This class is only meant to be used within EXT:install and is not part of the TYPO3 Core API.
Table of Contents
Constants
- NODE_RESOLVED_AS = 'nodeResolvedAs'
- TOPIC_TYPE_CALLED = 'called'
- TOPIC_TYPE_DROPPED = 'dropped'
- TOPIC_TYPE_REQUIRED = 'required'
- TOPIC_TYPE_UNUSED = 'unused'
Properties
- $currentCodeLine : int
- $flatMatcherDefinitions : array<string|int, mixed>
- Helper property containing an array derived from $this->matcherDefinitions created in __construct() if needed.
- $isCurrentLineIgnored : bool
- $isFullFileIgnored : bool
- $matcherDefinitions : array<string|int, mixed>
- Incoming main configuration array.
- $matches : array<string|int, mixed>
Methods
- __construct() : mixed
- Prepare $this->flatMatcherDefinitions once and validate config
- enterNode() : void|null
- Called by PhpParser.
- getMatches() : array<string|int, mixed>
- Return list of matches after processing
- handleCalledArguments() : bool
- handleDroppedArguments() : bool
- handleRequiredArguments() : bool
- handleUnusedArguments() : bool
- initializeFlatMatcherDefinitions() : mixed
- Initialize helper lookup array $this->flatMatcherDefinitions.
- isArgumentUnpackingUsed() : bool
- Test if one argument is given as "...$someArray".
- isFileIgnored() : bool
- Return true if the node is ignored since the entire file is ignored.
- isLineIgnored() : bool
- Returns true if a comment before a statement is marked as "@extensionScannerIgnoreLine"
- validateMatcherDefinitionKeys() : void
- validateMatcherDefinitions() : mixed
- Some matcher need specific keys in the array definition to work properly.
- validateMatcherDefinitionsTopicRequirements() : void
Constants
NODE_RESOLVED_AS
public
mixed
NODE_RESOLVED_AS
= 'nodeResolvedAs'
TOPIC_TYPE_CALLED
protected
mixed
TOPIC_TYPE_CALLED
= 'called'
TOPIC_TYPE_DROPPED
protected
mixed
TOPIC_TYPE_DROPPED
= 'dropped'
TOPIC_TYPE_REQUIRED
protected
mixed
TOPIC_TYPE_REQUIRED
= 'required'
TOPIC_TYPE_UNUSED
protected
mixed
TOPIC_TYPE_UNUSED
= 'unused'
Properties
$currentCodeLine
protected
int
$currentCodeLine
= 0
Helper variable for ignored line detection
$flatMatcherDefinitions
Helper property containing an array derived from $this->matcherDefinitions created in __construct() if needed.
protected
array<string|int, mixed>
$flatMatcherDefinitions
= []
$isCurrentLineIgnored
protected
bool
$isCurrentLineIgnored
= false
True if line with $lastIgnoredLineNumber is ignored
$isFullFileIgnored
protected
bool
$isFullFileIgnored
= false
True if the entire file is ignored due to a @extensionScannerIgnoreFile class comment
$matcherDefinitions
Incoming main configuration array.
protected
array<string|int, mixed>
$matcherDefinitions
= []
$matches
protected
array<string|int, mixed>
$matches
= []
List of accumulated matches
Methods
__construct()
Prepare $this->flatMatcherDefinitions once and validate config
public
__construct(array<string|int, mixed> $matcherDefinitions) : mixed
Parameters
- $matcherDefinitions : array<string|int, mixed>
-
Incoming main configuration
enterNode()
Called by PhpParser.
public
enterNode(Node $node) : void|null
Test for "->deprecated()" (weak match)
Parameters
- $node : Node
Return values
void|nullgetMatches()
Return list of matches after processing
public
getMatches() : array<string|int, mixed>
Return values
array<string|int, mixed>handleCalledArguments()
protected
handleCalledArguments(Node $node, Node $resolvedNode) : bool
Parameters
- $node : Node
-
reflects invocation, e.g.
GeneralUtility::makeInstance(MyClass::class, 123)
- $resolvedNode : Node
-
reflects resolved and actual usage, e.g.
new MyClass(123)
Return values
boolhandleDroppedArguments()
protected
handleDroppedArguments(Node $node, Node $resolvedNode) : bool
Parameters
- $node : Node
-
reflects invocation, e.g.
GeneralUtility::makeInstance(MyClass::class, 123)
- $resolvedNode : Node
-
reflects resolved and actual usage, e.g.
new MyClass(123)
Return values
boolhandleRequiredArguments()
protected
handleRequiredArguments(Node $node, Node $resolvedNode) : bool
Parameters
- $node : Node
-
reflects invocation, e.g.
GeneralUtility::makeInstance(MyClass::class, 123)
- $resolvedNode : Node
-
reflects resolved and actual usage, e.g.
new MyClass(123)
Return values
boolhandleUnusedArguments()
protected
handleUnusedArguments(Node $node, Node $resolvedNode) : bool
Parameters
- $node : Node
-
reflects invocation, e.g.
GeneralUtility::makeInstance(MyClass::class, 123)
- $resolvedNode : Node
-
reflects resolved and actual usage, e.g.
new MyClass(123)
Return values
boolinitializeFlatMatcherDefinitions()
Initialize helper lookup array $this->flatMatcherDefinitions.
protected
initializeFlatMatcherDefinitions() : mixed
For class\name->foo matcherDefinitions, it creates a helper array containing only the method name as array keys for "weak" matches.
If methods with the same name from different classes are defined, a "candidate" array is created containing details of single possible matches for further analysis.
Tags
isArgumentUnpackingUsed()
Test if one argument is given as "...$someArray".
protected
isArgumentUnpackingUsed([array<string|int, mixed> $arguments = [] ]) : bool
If so, it kinda defeats any "argument count" approach.
Parameters
- $arguments : array<string|int, mixed> = []
-
List of arguments
Return values
boolisFileIgnored()
Return true if the node is ignored since the entire file is ignored.
protected
isFileIgnored(Node $node) : bool
Sets ignore status if a class node is given having the annotation.
Parameters
- $node : Node
Return values
boolisLineIgnored()
Returns true if a comment before a statement is marked as "@extensionScannerIgnoreLine"
protected
isLineIgnored(Node $node) : bool
Parameters
- $node : Node
Return values
boolvalidateMatcherDefinitionKeys()
protected
validateMatcherDefinitionKeys(string $key, array<string|int, mixed> $matcherDefinition[, array<string|int, mixed> $requiredArrayKeys = [] ]) : void
Parameters
- $key : string
- $matcherDefinition : array<string|int, mixed>
- $requiredArrayKeys : array<string|int, mixed> = []
validateMatcherDefinitions()
Some matcher need specific keys in the array definition to work properly.
protected
validateMatcherDefinitions([array<string|int, mixed> $requiredArrayKeys = [] ]) : mixed
This method is called typically in __construct() of a matcher to verify these are given. This method is a measure against broken core configuration. It should be pretty quick and is only called in __construct() once, no kitten should be harmed.
This method works on $this->matcherDefinitions.
Parameters
- $requiredArrayKeys : array<string|int, mixed> = []
-
List of required keys for single matchers
Tags
validateMatcherDefinitionsTopicRequirements()
protected
validateMatcherDefinitionsTopicRequirements(array<string|int, mixed> $topicRequirements) : void
Parameters
- $topicRequirements : array<string|int, mixed>