[!!!][TASK] Remove ExtJS Debugging and $GLOBALS['error']
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / ExtensionScanner / Php / Matcher / FunctionCallMatcher.php
1 <?php
2 declare(strict_types=1);
3 namespace TYPO3\CMS\Install\ExtensionScanner\Php\Matcher;
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
18 use PhpParser\Node;
19 use PhpParser\Node\Expr\FuncCall;
20 use PhpParser\Node\Name\FullyQualified;
21
22 /**
23 * Find usages of global function calls which were removed / deprecated.
24 * This is a strong match.
25 */
26 class FunctionCallMatcher extends AbstractCoreMatcher
27 {
28 /**
29 * Prepare $this->flatMatcherDefinitions once
30 *
31 * @param array $matcherDefinitions Incoming main configuration
32 */
33 public function __construct(array $matcherDefinitions)
34 {
35 $this->matcherDefinitions = $matcherDefinitions;
36 $this->validateMatcherDefinitions(['numberOfMandatoryArguments', 'maximumNumberOfArguments']);
37 }
38
39 /**
40 * Called by PhpParser.
41 * Test for "removedFunction()" (strong match)
42 *
43 * @param Node $node
44 */
45 public function enterNode(Node $node)
46 {
47 // Match method call (not static)
48 if (!$this->isFileIgnored($node)
49 && !$this->isLineIgnored($node)
50 && $node instanceof FuncCall
51 && $node->name instanceof FullyQualified
52 && in_array($node->name->toString(), array_keys($this->matcherDefinitions), true)
53 ) {
54 $functionName = $node->name->toString();
55 $matchDefinition = $this->matcherDefinitions[$functionName];
56
57 $numberOfArguments = count($node->args);
58 $isArgumentUnpackingUsed = $this->isArgumentUnpackingUsed($node->args);
59
60 if ($isArgumentUnpackingUsed
61 || ($numberOfArguments >= $matchDefinition['numberOfMandatoryArguments']
62 && $numberOfArguments <= $matchDefinition['maximumNumberOfArguments'])
63 ) {
64 $this->matches[] = [
65 'restFiles' => $matchDefinition['restFiles'],
66 'line' => $node->getAttribute('startLine'),
67 'message' => 'Call to function "' . $functionName . '"',
68 'indicator' => 'strong',
69 ];
70 }
71 }
72 }
73 }