‪TYPO3CMS  ‪main
CodeStatistics.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\Stmt\Class_;
22 use PhpParser\NodeVisitorAbstract;
23 
29 class ‪CodeStatistics extends NodeVisitorAbstract
30 {
34  protected ‪$isCurrentFileIgnored = false;
35 
39  protected ‪$numberOfIgnoreLines = 0;
40 
44  protected ‪$numberOfEffectiveCodeLines = 0;
45 
49  protected ‪$currentLineNumber = 0;
50 
54  public function ‪enterNode(Node $node): null
55  {
56  $startLineOfNode = $node->getAttribute('startLine');
57  if ($startLineOfNode !== $this->currentLineNumber) {
58  $this->currentLineNumber = $startLineOfNode;
59  $this->numberOfEffectiveCodeLines++;
60 
61  // Class statements may contain the @extensionScannerIgnoreFile statements
62  if ($node instanceof Class_) {
63  $comments = $node->getAttribute('comments');
64  if (!empty($comments)) {
65  foreach ($comments as $comment) {
66  if (str_contains($comment->getText(), '@extensionScannerIgnoreFile')) {
67  $this->isCurrentFileIgnored = true;
68  break;
69  }
70  }
71  }
72  }
73 
74  // First node of line may contain the @extensionScannerIgnoreLine comment
75  $comments = $node->getAttribute('comments');
76  if (!empty($comments)) {
77  foreach ($comments as $comment) {
78  if (str_contains($comment->getText(), '@extensionScannerIgnoreLine')) {
79  $this->numberOfIgnoreLines++;
80  break;
81  }
82  }
83  }
84  }
85  return null;
86  }
87 
94  public function ‪isFileIgnored()
95  {
97  }
98 
106  public function ‪getNumberOfEffectiveCodeLines()
107  {
109  }
110 
117  public function ‪getNumberOfIgnoredLines()
118  {
120  }
121 }
‪TYPO3\CMS\Install\ExtensionScanner\Php\CodeStatistics\$isCurrentFileIgnored
‪bool $isCurrentFileIgnored
Definition: CodeStatistics.php:33
‪TYPO3\CMS\Install\ExtensionScanner\Php\CodeStatistics\isFileIgnored
‪bool isFileIgnored()
Definition: CodeStatistics.php:90
‪TYPO3\CMS\Install\ExtensionScanner\Php\CodeStatistics
Definition: CodeStatistics.php:30
‪TYPO3\CMS\Install\ExtensionScanner\Php\CodeStatistics\$numberOfIgnoreLines
‪int $numberOfIgnoreLines
Definition: CodeStatistics.php:37
‪TYPO3\CMS\Install\ExtensionScanner\Php\CodeStatistics\getNumberOfIgnoredLines
‪int getNumberOfIgnoredLines()
Definition: CodeStatistics.php:113
‪TYPO3\CMS\Install\ExtensionScanner\Php\CodeStatistics\$currentLineNumber
‪int $currentLineNumber
Definition: CodeStatistics.php:45
‪TYPO3\CMS\Install\ExtensionScanner\Php
Definition: CodeStatistics.php:18
‪TYPO3\CMS\Install\ExtensionScanner\Php\CodeStatistics\getNumberOfEffectiveCodeLines
‪int getNumberOfEffectiveCodeLines()
Definition: CodeStatistics.php:102
‪TYPO3\CMS\Install\ExtensionScanner\Php\CodeStatistics\enterNode
‪enterNode(Node $node)
Definition: CodeStatistics.php:50
‪TYPO3\CMS\Install\ExtensionScanner\Php\CodeStatistics\$numberOfEffectiveCodeLines
‪int $numberOfEffectiveCodeLines
Definition: CodeStatistics.php:41