|
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
|
23 |
|
public function __construct( |
|
17
|
|
|
private readonly MissingDocblockConfigDTO $docblockConfigDTO, |
|
18
|
|
|
) { |
|
19
|
23 |
|
} |
|
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
|
23 |
|
public function analyze(string $code, string $filename): array |
|
29
|
|
|
{ |
|
30
|
23 |
|
$parser = (new ParserFactory())->createForHostVersion(); |
|
31
|
23 |
|
$ast = $parser->parse($code); |
|
32
|
|
|
|
|
33
|
23 |
|
$traverser = new NodeTraverser(); |
|
34
|
23 |
|
$visitor = new MissingDocBlockVisitor($filename, $this->docblockConfigDTO); |
|
35
|
|
|
|
|
36
|
23 |
|
$traverser->addVisitor(new NameResolver()); |
|
37
|
23 |
|
$traverser->addVisitor($visitor); |
|
38
|
23 |
|
$traverser->traverse($ast); |
|
|
|
|
|
|
39
|
|
|
|
|
40
|
23 |
|
return $visitor->missingDocBlocks; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
23 |
|
public function getMissingDocblocks(string $code, string $filename): array |
|
44
|
|
|
{ |
|
45
|
23 |
|
return $this->analyze($code, $filename); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function getColor(): string |
|
49
|
|
|
{ |
|
50
|
|
|
return 'red'; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function getStatColor(float $count, array $thresholds): string |
|
54
|
|
|
{ |
|
55
|
|
|
if (!isset($thresholds['missingDocBlock'])) { |
|
56
|
|
|
return 'white'; |
|
57
|
|
|
} |
|
58
|
|
|
if ($count <= $thresholds['missingDocBlock']) { |
|
59
|
|
|
return 'green'; |
|
60
|
|
|
} |
|
61
|
|
|
$this->exceedThreshold = true; |
|
62
|
|
|
return 'red'; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function hasExceededThreshold(): bool |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->exceedThreshold; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function getName(): string |
|
71
|
|
|
{ |
|
72
|
|
|
return 'missingDocblock'; |
|
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