‪TYPO3CMS  10.4
FunctionCallMatcher.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PhpParser\Node;
21 use PhpParser\Node\Expr\FuncCall;
22 use PhpParser\Node\Name\FullyQualified;
23 
30 {
36  public function ‪__construct(array ‪$matcherDefinitions)
37  {
38  $this->matcherDefinitions = ‪$matcherDefinitions;
39  $this->‪validateMatcherDefinitions(['numberOfMandatoryArguments', 'maximumNumberOfArguments']);
40  }
41 
48  public function ‪enterNode(Node $node)
49  {
50  // Match method call (not static)
51  if (!$this->‪isFileIgnored($node)
52  && !$this->‪isLineIgnored($node)
53  && $node instanceof FuncCall
54  && $node->name instanceof FullyQualified
55  && array_key_exists($node->name->toString(), $this->matcherDefinitions)
56  ) {
57  $functionName = $node->name->toString();
58  $matchDefinition = $this->matcherDefinitions[$functionName];
59 
60  $numberOfArguments = count($node->args);
61  $isArgumentUnpackingUsed = $this->‪isArgumentUnpackingUsed($node->args);
62 
63  if ($isArgumentUnpackingUsed
64  || ($numberOfArguments >= $matchDefinition['numberOfMandatoryArguments']
65  && $numberOfArguments <= $matchDefinition['maximumNumberOfArguments'])
66  ) {
67  $this->matches[] = [
68  'restFiles' => $matchDefinition['restFiles'],
69  'line' => $node->getAttribute('startLine'),
70  'message' => 'Call to function "' . $functionName . '"',
71  'indicator' => 'strong',
72  ];
73  }
74  }
75  }
76 }
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\FunctionCallMatcher\__construct
‪__construct(array $matcherDefinitions)
Definition: FunctionCallMatcher.php:36
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\AbstractCoreMatcher\isArgumentUnpackingUsed
‪bool isArgumentUnpackingUsed(array $arguments=[])
Definition: AbstractCoreMatcher.php:164
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher
Definition: AbstractCoreMatcher.php:18
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\AbstractCoreMatcher\isLineIgnored
‪bool isLineIgnored(Node $node)
Definition: AbstractCoreMatcher.php:181
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\AbstractCoreMatcher
Definition: AbstractCoreMatcher.php:34
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\AbstractCoreMatcher\validateMatcherDefinitions
‪validateMatcherDefinitions(array $requiredArrayKeys=[])
Definition: AbstractCoreMatcher.php:88
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\AbstractCoreMatcher\isFileIgnored
‪bool isFileIgnored(Node $node)
Definition: AbstractCoreMatcher.php:214
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\AbstractCoreMatcher\$matcherDefinitions
‪array $matcherDefinitions
Definition: AbstractCoreMatcher.php:41
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\FunctionCallMatcher\enterNode
‪enterNode(Node $node)
Definition: FunctionCallMatcher.php:48
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\FunctionCallMatcher
Definition: FunctionCallMatcher.php:30