‪TYPO3CMS  9.5
CodeStatistics.php
Go to the documentation of this file.
1 <?php
2 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 
18 use PhpParser\Node;
19 use PhpParser\Node\Stmt\Class_;
20 use PhpParser\NodeVisitorAbstract;
21 
27 class ‪CodeStatistics extends NodeVisitorAbstract
28 {
32  protected ‪$isCurrentFileIgnored = 0;
33 
37  protected ‪$numberOfIgnoreLines = 0;
38 
42  protected ‪$numberOfEffectiveCodeLines = 0;
43 
47  protected ‪$currentLineNumber = 0;
48 
54  public function ‪enterNode(Node $node)
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 (strstr($comment->getText(), '@extensionScannerIgnoreFile') !== false) {
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 (strstr($comment->getText(), '@extensionScannerIgnoreLine') !== false) {
79  $this->numberOfIgnoreLines++;
80  break;
81  }
82  }
83  }
84  }
85  }
86 
93  public function ‪isFileIgnored()
94  {
96  }
97 
105  public function ‪getNumberOfEffectiveCodeLines()
106  {
108  }
109 
116  public function ‪getNumberOfIgnoredLines()
117  {
119  }
120 }
‪TYPO3\CMS\Install\ExtensionScanner\Php\CodeStatistics
Definition: CodeStatistics.php:28
‪TYPO3\CMS\Install\ExtensionScanner\Php\CodeStatistics\$numberOfIgnoreLines
‪int $numberOfIgnoreLines
Definition: CodeStatistics.php:35
‪TYPO3\CMS\Install\ExtensionScanner\Php\CodeStatistics\getNumberOfIgnoredLines
‪int getNumberOfIgnoredLines()
Definition: CodeStatistics.php:112
‪TYPO3\CMS\Install\ExtensionScanner\Php\CodeStatistics\$currentLineNumber
‪int $currentLineNumber
Definition: CodeStatistics.php:43
‪TYPO3\CMS\Install\ExtensionScanner\Php
Definition: CodeStatistics.php:3
‪TYPO3\CMS\Install\ExtensionScanner\Php\CodeStatistics\isFileIgnored
‪int isFileIgnored()
Definition: CodeStatistics.php:89
‪TYPO3\CMS\Install\ExtensionScanner\Php\CodeStatistics\$isCurrentFileIgnored
‪int $isCurrentFileIgnored
Definition: CodeStatistics.php:31
‪TYPO3\CMS\Install\ExtensionScanner\Php\CodeStatistics\getNumberOfEffectiveCodeLines
‪int getNumberOfEffectiveCodeLines()
Definition: CodeStatistics.php:101
‪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:39