CommentVisitor::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 0
nc 1
nop 2
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 1
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