Passed
Push — main ( ecc027...46eee6 )
by mikhail
03:29
created

MissingDocBlockVisitor   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A enterNode() 0 20 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SavinMikhail\CommentsDensity\MissingDocblock\Visitors;
6
7
use PhpParser\Node;
8
use PhpParser\NodeVisitorAbstract;
9
use SavinMikhail\CommentsDensity\DTO\Output\CommentDTO;
0 ignored issues
show
Bug introduced by
The type SavinMikhail\CommentsDensity\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\MissingDocblock\MissingDocBlockAnalyzer;
11
use SavinMikhail\CommentsDensity\MissingDocblock\Visitors\Checkers\NodeNeedsDocblockChecker;
12
13
final class MissingDocBlockVisitor extends NodeVisitorAbstract
14
{
15
    /** @var CommentDTO[]  */
16
    public array $missingDocBlocks = [];
17
18 70
    public function __construct(
19
        private readonly string $filename,
20
        private readonly NodeNeedsDocblockChecker $nodeChecker,
21
    ) {
22 70
    }
23
24 70
    public function enterNode(Node $node): null
25
    {
26 70
        if (! $this->nodeChecker->requiresDocBlock($node)) {
27 70
            return null;
28
        }
29 50
        $docComment = $node->getDocComment();
30 50
        if ($docComment !== null) {
31 13
            return null;
32
        }
33
34 48
        $this->missingDocBlocks[] =
35 48
            new CommentDTO(
36 48
                MissingDocBlockAnalyzer::NAME, //todo: use methods from MissingDocBlockAnalyzer
37 48
                MissingDocBlockAnalyzer::COLOR,
38 48
                $this->filename,
39 48
                $node->getLine(),
0 ignored issues
show
Deprecated Code introduced by
The function PhpParser\Node::getLine() has been deprecated: Use getStartLine() instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

39
                /** @scrutinizer ignore-deprecated */ $node->getLine(),

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
40 48
                $this->nodeChecker->determineMissingContent(),
41 48
            );
42
43 48
        return null;
44
    }
45
}
46