‪TYPO3CMS  10.4
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 = 0;
35 
39  protected ‪$numberOfIgnoreLines = 0;
40 
44  protected ‪$numberOfEffectiveCodeLines = 0;
45 
49  protected ‪$currentLineNumber = 0;
50 
56  public function ‪enterNode(Node $node)
57  {
58  $startLineOfNode = $node->getAttribute('startLine');
59  if ($startLineOfNode !== $this->currentLineNumber) {
60  $this->currentLineNumber = $startLineOfNode;
61  $this->numberOfEffectiveCodeLines++;
62 
63  // Class statements may contain the @extensionScannerIgnoreFile statements
64  if ($node instanceof Class_) {
65  $comments = $node->getAttribute('comments');
66  if (!empty($comments)) {
67  foreach ($comments as $comment) {
68  if (strpos($comment->getText(), '@extensionScannerIgnoreFile') !== false) {
69  $this->isCurrentFileIgnored = true;
70  break;
71  }
72  }
73  }
74  }
75 
76  // First node of line may contain the @extensionScannerIgnoreLine comment
77  $comments = $node->getAttribute('comments');
78  if (!empty($comments)) {
79  foreach ($comments as $comment) {
80  if (strpos($comment->getText(), '@extensionScannerIgnoreLine') !== false) {
81  $this->numberOfIgnoreLines++;
82  break;
83  }
84  }
85  }
86  }
87  }
88 
95  public function ‪isFileIgnored()
96  {
98  }
99 
107  public function ‪getNumberOfEffectiveCodeLines()
108  {
110  }
111 
118  public function ‪getNumberOfIgnoredLines()
119  {
121  }
122 }
‪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:114
‪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\isFileIgnored
‪int isFileIgnored()
Definition: CodeStatistics.php:91
‪TYPO3\CMS\Install\ExtensionScanner\Php\CodeStatistics\$isCurrentFileIgnored
‪int $isCurrentFileIgnored
Definition: CodeStatistics.php:33
‪TYPO3\CMS\Install\ExtensionScanner\Php\CodeStatistics\getNumberOfEffectiveCodeLines
‪int getNumberOfEffectiveCodeLines()
Definition: CodeStatistics.php:103
‪TYPO3\CMS\Install\ExtensionScanner\Php\CodeStatistics\enterNode
‪enterNode(Node $node)
Definition: CodeStatistics.php:52
‪TYPO3\CMS\Install\ExtensionScanner\Php\CodeStatistics\$numberOfEffectiveCodeLines
‪int $numberOfEffectiveCodeLines
Definition: CodeStatistics.php:41