‪TYPO3CMS  10.4
PropertyAnnotationMatcher.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\Comment\Doc;
21 use PhpParser\Node;
22 use PhpParser\Node\Stmt\Property;
23 use PhpParser\Node\Stmt\PropertyProperty;
24 
30 {
36  public function ‪__construct(array ‪$matcherDefinitions)
37  {
38  $this->matcherDefinitions = ‪$matcherDefinitions;
40  }
41 
48  public function ‪enterNode(Node $node)
49  {
50  if ($node instanceof Property
51  && ($property = reset($node->props)) instanceof PropertyProperty
52  && ($docComment = $node->getDocComment()) instanceof Doc
53  && !$this->isFileIgnored($node)
54  && !$this->isLineIgnored($node)
55  ) {
57  $isPossibleMatch = false;
58  $match = [
59  'restFiles' => [],
60  'line' => $property->getAttribute('startLine'),
61  'indicator' => 'strong',
62  ];
63 
64  ‪$matches = [];
65  preg_match_all(
66  '/\s*\s@(?<annotations>[^\s.]*).*\n/',
67  $docComment->getText(),
69  );
70 
71  foreach (‪$matches['annotations'] as $annotation) {
72  $annotation = '@' . $annotation;
73 
74  if (!isset($this->matcherDefinitions[$annotation])) {
75  continue;
76  }
77 
78  $isPossibleMatch = true;
79  $match['message'] = 'Property "' . $property->name . '" uses an ' . $annotation . ' annotation.';
80  $match['restFiles'] = array_unique(array_merge(
81  $match['restFiles'],
82  $this->matcherDefinitions[$annotation]['restFiles']
83  ));
84  }
85 
86  if ($isPossibleMatch) {
87  $this->matches[] = $match;
88  }
89  }
90  }
91 }
‪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\PropertyAnnotationMatcher\enterNode
‪enterNode(Node $node)
Definition: PropertyAnnotationMatcher.php:48
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\AbstractCoreMatcher\$matches
‪array $matches
Definition: AbstractCoreMatcher.php:45
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\PropertyAnnotationMatcher
Definition: PropertyAnnotationMatcher.php:30
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\AbstractCoreMatcher\validateMatcherDefinitions
‪validateMatcherDefinitions(array $requiredArrayKeys=[])
Definition: AbstractCoreMatcher.php:88
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\AbstractCoreMatcher\$matcherDefinitions
‪array $matcherDefinitions
Definition: AbstractCoreMatcher.php:41
‪TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\PropertyAnnotationMatcher\__construct
‪__construct(array $matcherDefinitions)
Definition: PropertyAnnotationMatcher.php:36