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

MissingDocBlockVisitor::requiresDocBlock()   D

Complexity

Conditions 18
Paths 10

Size

Total Lines 38
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 18

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 18
eloc 19
c 2
b 0
f 0
nc 10
nop 1
dl 0
loc 38
ccs 20
cts 20
cp 1
crap 18
rs 4.8666

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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