Passed
Push — main ( 7afa9b...0a3ee1 )
by mikhail
03:21
created

MissingDocBlockVisitor::methodRequiresAdditionalDocBlock()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 4
Bugs 2 Features 0
Metric Value
cc 2
eloc 3
c 4
b 2
f 0
nc 2
nop 1
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SavinMikhail\CommentsDensity\MissingDocblock;
6
7
use ArrayAccess;
8
use Iterator;
9
use PhpParser\Node;
10
use PhpParser\Node\ComplexType;
11
use PhpParser\Node\Identifier;
12
use PhpParser\Node\Name;
13
use PhpParser\Node\Stmt\Class_;
14
use PhpParser\Node\Stmt\ClassConst;
15
use PhpParser\Node\Stmt\ClassMethod;
16
use PhpParser\Node\Stmt\Enum_;
17
use PhpParser\Node\Stmt\Function_;
18
use PhpParser\Node\Stmt\Interface_;
19
use PhpParser\Node\Stmt\Property;
20
use PhpParser\Node\Stmt\Trait_;
21
use PhpParser\NodeTraverser;
22
use PhpParser\NodeVisitorAbstract;
23
use ReflectionClass;
24
use SavinMikhail\CommentsDensity\DTO\Input\MissingDocblockConfigDTO;
0 ignored issues
show
Bug introduced by
The type SavinMikhail\CommentsDen...issingDocblockConfigDTO 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...
25
26
use function class_exists;
27
use function in_array;
28
29
final class MissingDocBlockVisitor extends NodeVisitorAbstract
30
{
31
    public array $missingDocBlocks = [];
32
33 51
    public function __construct(
34
        private readonly string $filename,
35
        private readonly DocBlockChecker $docBlockChecker,
0 ignored issues
show
Bug introduced by
The type SavinMikhail\CommentsDen...ocblock\DocBlockChecker 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...
36
    ) {
37 51
    }
38
39 51
    public function enterNode(Node $node): void
40
    {
41 51
        if (! $this->docBlockChecker->requiresDocBlock($node)) {
42 51
            return;
43
        }
44 33
        $docComment = $node->getDocComment();
45 33
        if ($docComment !== null) {
46 12
            return;
47
        }
48 31
        $this->missingDocBlocks[] = [
49 31
            'type' => 'missingDocblock',
50 31
            'content' => '',
51 31
            'file' => $this->filename,
52 31
            'line' => $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

52
            'line' => /** @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...
53 31
        ];
54
    }
55
}
56