|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SavinMikhail\CommentsDensity\MissingDocblock; |
|
6
|
|
|
|
|
7
|
|
|
use PhpParser\Node; |
|
8
|
|
|
use PhpParser\NodeVisitorAbstract; |
|
9
|
|
|
use SavinMikhail\CommentsDensity\DTO\Input\MissingDocblockConfigDTO; |
|
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
final class MissingDocBlockVisitor extends NodeVisitorAbstract |
|
12
|
|
|
{ |
|
13
|
|
|
public array $missingDocBlocks = []; |
|
14
|
|
|
private string $filename; |
|
15
|
|
|
private MissingDocblockConfigDTO $config; |
|
16
|
|
|
|
|
17
|
23 |
|
public function __construct(string $filename, MissingDocblockConfigDTO $config) |
|
18
|
|
|
{ |
|
19
|
23 |
|
$this->filename = $filename; |
|
20
|
23 |
|
$this->config = $config; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
23 |
|
public function enterNode(Node $node): void |
|
24
|
|
|
{ |
|
25
|
23 |
|
if ($this->requiresDocBlock($node)) { |
|
26
|
14 |
|
$docComment = $node->getDocComment(); |
|
27
|
14 |
|
if ($docComment === null) { |
|
28
|
12 |
|
$this->missingDocBlocks[] = [ |
|
29
|
12 |
|
'type' => 'missingDocblock', |
|
30
|
12 |
|
'content' => '', |
|
31
|
12 |
|
'file' => $this->filename, |
|
32
|
12 |
|
'line' => $node->getLine(), |
|
|
|
|
|
|
33
|
12 |
|
]; |
|
34
|
|
|
} |
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
23 |
|
private function requiresDocBlock(Node $node): bool |
|
39
|
|
|
{ |
|
40
|
23 |
|
if ($node instanceof Node\Stmt\Class_ && $this->config->class) { |
|
41
|
11 |
|
return !$node->isAnonymous(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
23 |
|
if ($node instanceof Node\Stmt\Trait_ && $this->config->trait) { |
|
45
|
1 |
|
return true; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
23 |
|
if ($node instanceof Node\Stmt\Interface_ && $this->config->interface) { |
|
49
|
1 |
|
return true; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
23 |
|
if ($node instanceof Node\Stmt\Enum_ && $this->config->enum) { |
|
53
|
1 |
|
return true; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
23 |
|
if ($node instanceof Node\Stmt\Function_ && $this->config->function) { |
|
57
|
1 |
|
return true; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
23 |
|
if ($node instanceof Node\Stmt\ClassMethod && $this->config->function) { |
|
61
|
3 |
|
return true; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
23 |
|
if ($node instanceof Node\Stmt\Property && $this->config->property) { |
|
65
|
5 |
|
return true; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
23 |
|
if ($node instanceof Node\Stmt\ClassConst && $this->config->constant) { |
|
69
|
1 |
|
return true; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
23 |
|
return false; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths