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