CommentVisitor   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 94.12%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 15
dl 0
loc 29
ccs 16
cts 17
cp 0.9412
rs 10
c 1
b 0
f 1
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A enterNode() 0 19 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SavinMikhail\CommentsDensity\AnalyzeComments\Analyzer\Visitors;
6
7
use PhpParser\Node;
8
use PhpParser\NodeVisitorAbstract;
9
use SavinMikhail\CommentsDensity\AnalyzeComments\Analyzer\DTO\Output\CommentDTO;
0 ignored issues
show
Bug introduced by
The type SavinMikhail\CommentsDen...r\DTO\Output\CommentDTO was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use SavinMikhail\CommentsDensity\AnalyzeComments\Comments\CommentTypeFactory;
0 ignored issues
show
Bug introduced by
The type SavinMikhail\CommentsDen...ents\CommentTypeFactory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
12
final class CommentVisitor extends NodeVisitorAbstract
13
{
14
    /** @var CommentDTO[] */
15
    public array $comments = [];
16
17 31
    public function __construct(
18
        private readonly string $filename,
19
        private readonly CommentTypeFactory $commentFactory,
20 31
    ) {}
21
22 31
    public function enterNode(Node $node): null
23
    {
24 31
        $comments = array_unique(array_filter([$node->getDocComment(), ...$node->getComments()]));
25 31
        foreach ($comments as $comment) {
26 14
            $commentType = $this->commentFactory->classifyComment($comment->getText());
27 14
            if ($commentType === null) {
28
                continue;
29
            }
30 14
            $this->comments[] =
31 14
                new CommentDTO(
32 14
                    $commentType->getName(),
33 14
                    $commentType->getColor(),
34 14
                    $this->filename,
35 14
                    $comment->getStartLine(),
36 14
                    $comment->getText(),
37 14
                );
38
        }
39
40 31
        return null;
41
    }
42
}
43