‪TYPO3CMS  ‪main
MethodArgumentRequiredMatcher.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\MethodCall;
22 
30 {
36  public function ‪__construct(array ‪$matcherDefinitions)
37  {
38  $this->matcherDefinitions = ‪$matcherDefinitions;
39  $this->‪validateMatcherDefinitions(['numberOfMandatoryArguments']);
41  }
42 
47  public function ‪enterNode(Node $node): null
48  {
49  // Match method call (not static)
50  if (!$this->‪isFileIgnored($node)
51  && !$this->‪isLineIgnored($node)
52  && $node instanceof MethodCall
53  && array_key_exists($node->name->name, $this->flatMatcherDefinitions)
54  ) {
55  $match = [
56  'restFiles' => [],
57  'line' => $node->getAttribute('startLine'),
58  'indicator' => 'weak',
59  ];
60 
61  $isArgumentUnpackingUsed = $this->‪isArgumentUnpackingUsed($node->args);
62 
63  $numberOfArguments = count($node->args);
64  $isPossibleMatch = false;
65  foreach ($this->flatMatcherDefinitions[$node->name->name]['candidates'] as $candidate) {
66  // A method call is considered a match if it is not called with argument unpacking
67  // and number of used arguments is lower than numberOfMandatoryArguments
68  if (!$isArgumentUnpackingUsed
69  && $numberOfArguments < $candidate['numberOfMandatoryArguments']
70  && $numberOfArguments <= $candidate['maximumNumberOfArguments']
71  ) {
72  $isPossibleMatch = true;
73  $match['message'] = 'Method ' . $node->name->name . '() needs at least ' . $candidate['numberOfMandatoryArguments'] . ' arguments.';
74  $match['restFiles'] = array_unique(array_merge($match['restFiles'], $candidate['restFiles']));
75  }
76  }
77  if ($isPossibleMatch) {
78  $this->matches[] = $match;
79  }
80  }
81  return null;
82  }
83 }
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\AbstractCoreMatcher\isArgumentUnpackingUsed
‪isArgumentUnpackingUsed(array $arguments=[])
Definition: AbstractCoreMatcher.php:161
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\AbstractCoreMatcher\isLineIgnored
‪isLineIgnored(Node $node)
Definition: AbstractCoreMatcher.php:175
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\MethodArgumentRequiredMatcher\__construct
‪__construct(array $matcherDefinitions)
Definition: MethodArgumentRequiredMatcher.php:36
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher
Definition: AbstractCoreMatcher.php:18
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\AbstractCoreMatcher
Definition: AbstractCoreMatcher.php:34
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\MethodArgumentRequiredMatcher
Definition: MethodArgumentRequiredMatcher.php:30
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\AbstractCoreMatcher\isFileIgnored
‪isFileIgnored(Node $node)
Definition: AbstractCoreMatcher.php:210
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\AbstractCoreMatcher\validateMatcherDefinitions
‪validateMatcherDefinitions(array $requiredArrayKeys=[])
Definition: AbstractCoreMatcher.php:86
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\AbstractCoreMatcher\$matcherDefinitions
‪array $matcherDefinitions
Definition: AbstractCoreMatcher.php:41
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\AbstractCoreMatcher\initializeFlatMatcherDefinitions
‪initializeFlatMatcherDefinitions()
Definition: AbstractCoreMatcher.php:132
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\MethodArgumentRequiredMatcher\enterNode
‪enterNode(Node $node)
Definition: MethodArgumentRequiredMatcher.php:47