ConstructorArgumentMatcher

class \TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\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

Table of Contents

Constants

NODE_RESOLVED_AS  : string = 'nodeResolvedAs'
TOPIC_TYPE_CALLED  : string = 'called'
TOPIC_TYPE_DROPPED  : string = 'dropped'
TOPIC_TYPE_REQUIRED  : string = 'required'
TOPIC_TYPE_UNUSED  : string = 'unused'

Properties

$currentCodeLine  : int
Helper variable for ignored line detection
$flatMatcherDefinitions  : array<string, array{candidates: list>}>
Helper property containing an array derived from $this->matcherDefinitions created in __construct() if needed.
$isCurrentLineIgnored  : bool
True if line with $lastIgnoredLineNumber is ignored
$isFullFileIgnored  : bool
True if the entire file is ignored due to a @extensionScannerIgnoreFile class comment
$matcherDefinitions  : array<string, array<string, mixed>>
Incoming main configuration array.
$matches  : array<int, array<string, mixed>>

Methods

__construct()  : mixed
Prepare $this->flatMatcherDefinitions once and validate config
enterNode()  : null
Called by PhpParser.
getMatches()  : array<int, array<string, mixed>>
Return list of matches after processing
handleCalledArguments()  : bool
handleDroppedArguments()  : bool
handleRequiredArguments()  : bool
handleUnusedArguments()  : bool
initializeFlatMatcherDefinitions()  : void
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()  : void
Some matcher need specific keys in the array definition to work properly.
validateMatcherDefinitionsTopicRequirements()  : void

Constants

NODE_RESOLVED_AS

public string NODE_RESOLVED_AS = 'nodeResolvedAs'

TOPIC_TYPE_CALLED

protected string TOPIC_TYPE_CALLED = 'called'

TOPIC_TYPE_DROPPED

protected string TOPIC_TYPE_DROPPED = 'dropped'

TOPIC_TYPE_REQUIRED

protected string TOPIC_TYPE_REQUIRED = 'required'

TOPIC_TYPE_UNUSED

protected string TOPIC_TYPE_UNUSED = 'unused'

Properties

$currentCodeLine

Helper variable for ignored line detection

protected int $currentCodeLine = 0

$flatMatcherDefinitions

Helper property containing an array derived from $this->matcherDefinitions created in __construct() if needed.

protected array<string, array{candidates: list>}> $flatMatcherDefinitions = []

$isCurrentLineIgnored

True if line with $lastIgnoredLineNumber is ignored

protected bool $isCurrentLineIgnored = false

$isFullFileIgnored

True if the entire file is ignored due to a @extensionScannerIgnoreFile class comment

protected bool $isFullFileIgnored = false

$matcherDefinitions

Incoming main configuration array.

protected array<string, array<string, mixed>> $matcherDefinitions = []

$matches

protected array<int, array<string, mixed>> $matches = []

List of accumulated matches

Methods

__construct()

Prepare $this->flatMatcherDefinitions once and validate config

public __construct(array<string, array<string, mixed>> $matcherDefinitions) : mixed

Parameters

$matcherDefinitions : array<string, array<string, mixed>>

Incoming main configuration

enterNode()

Called by PhpParser.

public enterNode(Node $node) : null

Test for "->deprecated()" (weak match)

Parameters

$node : Node

Return values

null

getMatches()

Return list of matches after processing

public getMatches() : array<int, array<string, mixed>>

Return values

array<int, array<string, mixed>>

handleCalledArguments()

protected handleCalledArguments(Node $node, New_ $resolvedNode) : bool

Parameters

$node : Node

reflects invocation, e.g. GeneralUtility::makeInstance(MyClass::class, 123)

$resolvedNode : New_

reflects resolved and actual usage, e.g. new MyClass(123)

Return values

bool

handleDroppedArguments()

protected handleDroppedArguments(Node $node, New_ $resolvedNode) : bool

Parameters

$node : Node

reflects invocation, e.g. GeneralUtility::makeInstance(MyClass::class, 123)

$resolvedNode : New_

reflects resolved and actual usage, e.g. new MyClass(123)

Return values

bool

handleRequiredArguments()

protected handleRequiredArguments(Node $node, New_ $resolvedNode) : bool

Parameters

$node : Node

reflects invocation, e.g. GeneralUtility::makeInstance(MyClass::class, 123)

$resolvedNode : New_

reflects resolved and actual usage, e.g. new MyClass(123)

Return values

bool

handleUnusedArguments()

protected handleUnusedArguments(Node $node, New_ $resolvedNode) : bool

Parameters

$node : Node

reflects invocation, e.g. GeneralUtility::makeInstance(MyClass::class, 123)

$resolvedNode : New_

reflects resolved and actual usage, e.g. new MyClass(123)

Return values

bool

initializeFlatMatcherDefinitions()

Initialize helper lookup array $this->flatMatcherDefinitions.

protected initializeFlatMatcherDefinitions() : void

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

throws
RuntimeException

isArgumentUnpackingUsed()

Test if one argument is given as "...$someArray".

protected isArgumentUnpackingUsed([array<int, Arg|VariadicPlaceholder> $arguments = [] ]) : bool

If so, it kinda defeats any "argument count" approach.

A first-class callable ("foo(...)") has a single VariadicPlaceholder instead of arguments, so there is nothing to count either.

Parameters

$arguments : array<int, Arg|VariadicPlaceholder> = []

List of arguments

Return values

bool

isFileIgnored()

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

bool

isLineIgnored()

Returns true if a comment before a statement is marked as "@extensionScannerIgnoreLine"

protected isLineIgnored(Node $node) : bool

Parameters

$node : Node

Return values

bool

validateMatcherDefinitionKeys()

protected validateMatcherDefinitionKeys(string $key, array<string, mixed> $matcherDefinition[, array<int, string> $requiredArrayKeys = [] ]) : void

Parameters

$key : string
$matcherDefinition : array<string, mixed>
$requiredArrayKeys : array<int, string> = []

validateMatcherDefinitions()

Some matcher need specific keys in the array definition to work properly.

protected validateMatcherDefinitions([array<int, string> $requiredArrayKeys = [] ]) : void

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<int, string> = []

List of required keys for single matchers

Tags

throws
RuntimeException

validateMatcherDefinitionsTopicRequirements()

protected validateMatcherDefinitionsTopicRequirements(array<string, array<int, string>> $topicRequirements) : void

Parameters

$topicRequirements : array<string, array<int, string>>
On this page