‪TYPO3CMS  ‪main
ArrayDimensionMatcher.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\ArrayDimFetch;
23 
31 {
37  public function ‪__construct(array ‪$matcherDefinitions)
38  {
39  $this->matcherDefinitions = ‪$matcherDefinitions;
42  }
43 
47  public function ‪enterNode(Node $node): null
48  {
49  if (!$this->‪isFileIgnored($node)
50  && !$this->‪isLineIgnored($node)
51  && $node instanceof ArrayDimFetch
52  && isset($node->dim->value)
53  && array_key_exists($node->dim->value, $this->flatMatcherDefinitions)
54  ) {
55  $match = [
56  'restFiles' => [],
57  'line' => $node->getAttribute('startLine'),
58  'message' => 'Access to array key "' . $node->dim->value . '"',
59  'indicator' => 'weak',
60  ];
61 
62  foreach ($this->flatMatcherDefinitions[$node->dim->value]['candidates'] as $candidate) {
63  $match['restFiles'] = array_unique(array_merge($match['restFiles'], $candidate['restFiles']));
64  }
65  $this->matches[] = $match;
66  }
67  return null;
68  }
69 
74  {
75  $methodNameArray = [];
76  foreach ($this->matcherDefinitions as $fullArrayString => ‪$details) {
77  // Goal: find last part "foobar" of an array path "$foo['bar']['foobar']"
78  // Reverse string $foo['bar']['foobar']
79  $lastKey = strrev($fullArrayString);
80  // Cut off "['"
81  $lastKey = substr($lastKey, 2);
82  $lastKey = ‪GeneralUtility::trimExplode('\'[', $lastKey);
83  // Last key name
84  $lastKey = $lastKey[0];
85  // And reverse key name again
86  $lastKey = strrev($lastKey);
87 
88  if (!array_key_exists($lastKey, $methodNameArray)) {
89  $methodNameArray[$lastKey]['candidates'] = [];
90  }
91  $methodNameArray[$lastKey]['candidates'][] = $details;
92  }
93  $this->flatMatcherDefinitions = $methodNameArray;
94  }
95 }
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\AbstractCoreMatcher\isLineIgnored
‪isLineIgnored(Node $node)
Definition: AbstractCoreMatcher.php:175
‪TYPO3\CMS\Webhooks\Message\$details
‪identifier readonly UriInterface readonly array $details
Definition: MfaVerificationErrorOccurredMessage.php:37
‪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\AbstractCoreMatcher\isFileIgnored
‪isFileIgnored(Node $node)
Definition: AbstractCoreMatcher.php:205
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\AbstractCoreMatcher\validateMatcherDefinitions
‪validateMatcherDefinitions(array $requiredArrayKeys=[])
Definition: AbstractCoreMatcher.php:86
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\ArrayDimensionMatcher\enterNode
‪enterNode(Node $node)
Definition: ArrayDimensionMatcher.php:47
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\AbstractCoreMatcher\$matcherDefinitions
‪array $matcherDefinitions
Definition: AbstractCoreMatcher.php:41
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\ArrayDimensionMatcher\initializeLastArrayKeyNameArray
‪initializeLastArrayKeyNameArray()
Definition: ArrayDimensionMatcher.php:73
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\ArrayDimensionMatcher
Definition: ArrayDimensionMatcher.php:31
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\ArrayDimensionMatcher\__construct
‪__construct(array $matcherDefinitions)
Definition: ArrayDimensionMatcher.php:37
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static list< string > trimExplode(string $delim, string $string, bool $removeEmptyValues=false, int $limit=0)
Definition: GeneralUtility.php:822