1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SavinMikhail\CommentsDensity\MissingDocblock; |
6
|
|
|
|
7
|
|
|
use PhpParser\NodeTraverser; |
8
|
|
|
use PhpParser\ParserFactory; |
9
|
|
|
use PhpParser\NodeVisitor\NameResolver; |
10
|
|
|
use SavinMikhail\CommentsDensity\DTO\Input\MissingDocblockConfigDTO; |
|
|
|
|
11
|
|
|
|
12
|
|
|
final class MissingDocBlockAnalyzer |
13
|
|
|
{ |
14
|
|
|
private bool $exceedThreshold = false; |
15
|
|
|
|
16
|
55 |
|
public function __construct( |
17
|
|
|
private readonly MissingDocblockConfigDTO $docblockConfigDTO, |
18
|
|
|
) { |
19
|
55 |
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Analyzes the AST of a file for missing docblocks. |
23
|
|
|
* |
24
|
|
|
* @param string $code The code to analyze. |
25
|
|
|
* @param string $filename The filename of the code. |
26
|
|
|
* @return array The analysis results. |
27
|
|
|
*/ |
28
|
51 |
|
public function analyze(string $code, string $filename): array |
29
|
|
|
{ |
30
|
51 |
|
$parser = (new ParserFactory())->createForHostVersion(); |
31
|
51 |
|
$ast = $parser->parse($code); |
32
|
|
|
|
33
|
51 |
|
$traverser = new NodeTraverser(); |
34
|
51 |
|
$visitor = new MissingDocBlockVisitor( |
35
|
51 |
|
$filename, |
36
|
51 |
|
new DocBlockChecker($this->docblockConfigDTO, new MethodAnalyzer()) |
|
|
|
|
37
|
51 |
|
); |
38
|
|
|
|
39
|
51 |
|
$traverser->addVisitor(new NameResolver()); |
40
|
51 |
|
$traverser->addVisitor($visitor); |
41
|
51 |
|
$traverser->traverse($ast); |
|
|
|
|
42
|
|
|
|
43
|
51 |
|
return $visitor->missingDocBlocks; |
44
|
|
|
} |
45
|
|
|
|
46
|
51 |
|
public function getMissingDocblocks(string $code, string $filename): array |
47
|
|
|
{ |
48
|
51 |
|
return $this->analyze($code, $filename); |
49
|
|
|
} |
50
|
|
|
|
51
|
1 |
|
public function getColor(): string |
52
|
|
|
{ |
53
|
1 |
|
return 'red'; |
54
|
|
|
} |
55
|
|
|
|
56
|
2 |
|
public function getStatColor(float $count, array $thresholds): string |
57
|
|
|
{ |
58
|
2 |
|
if (!isset($thresholds['missingDocBlock'])) { |
59
|
1 |
|
return 'white'; |
60
|
|
|
} |
61
|
2 |
|
if ($count <= $thresholds['missingDocBlock']) { |
62
|
1 |
|
return 'green'; |
63
|
|
|
} |
64
|
2 |
|
$this->exceedThreshold = true; |
65
|
2 |
|
return 'red'; |
66
|
|
|
} |
67
|
|
|
|
68
|
2 |
|
public function hasExceededThreshold(): bool |
69
|
|
|
{ |
70
|
2 |
|
return $this->exceedThreshold; |
71
|
|
|
} |
72
|
|
|
|
73
|
1 |
|
public function getName(): string |
74
|
|
|
{ |
75
|
1 |
|
return 'missingDocblock'; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
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