|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SavinMikhail\CommentsDensity\MissingDocblock\Visitors\Checkers; |
|
6
|
|
|
|
|
7
|
|
|
use PhpParser\Node; |
|
8
|
|
|
use PhpParser\Node\Stmt\Class_; |
|
9
|
|
|
use PhpParser\Node\Stmt\ClassConst; |
|
10
|
|
|
use PhpParser\Node\Stmt\ClassMethod; |
|
11
|
|
|
use PhpParser\Node\Stmt\Enum_; |
|
12
|
|
|
use PhpParser\Node\Stmt\Function_; |
|
13
|
|
|
use PhpParser\Node\Stmt\Interface_; |
|
14
|
|
|
use PhpParser\Node\Stmt\Property; |
|
15
|
|
|
use PhpParser\Node\Stmt\Trait_; |
|
16
|
|
|
use SavinMikhail\CommentsDensity\Config\DTO\MissingDocblockConfigDTO; |
|
17
|
|
|
|
|
18
|
|
|
final readonly class NodeNeedsDocblockChecker |
|
|
|
|
|
|
19
|
|
|
{ |
|
20
|
|
|
public function __construct( |
|
21
|
|
|
private MissingDocblockConfigDTO $config, |
|
22
|
|
|
) {} |
|
23
|
|
|
|
|
24
|
|
|
public function requiresDocBlock(Node $node): bool |
|
25
|
|
|
{ |
|
26
|
|
|
if ($node instanceof Class_) { |
|
27
|
|
|
return $this->config->class && !$node->isAnonymous(); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
77 |
|
if ($this->isConfiguredNode($node)) { |
|
31
|
|
|
return true; |
|
32
|
|
|
} |
|
33
|
77 |
|
|
|
34
|
|
|
if ($this->isMethodOrFunction($node)) { |
|
35
|
77 |
|
return true; |
|
36
|
|
|
} |
|
37
|
77 |
|
|
|
38
|
58 |
|
return false; |
|
39
|
|
|
} |
|
40
|
58 |
|
|
|
41
|
|
|
private function isConfiguredNode(Node $node): bool |
|
42
|
|
|
{ |
|
43
|
77 |
|
return $this->isConfiguredTrait($node) |
|
44
|
15 |
|
|| $this->isConfiguredInterface($node) |
|
45
|
|
|
|| $this->isConfiguredEnum($node) |
|
46
|
|
|
|| $this->isConfiguredProperty($node) |
|
47
|
77 |
|
|| $this->isConfiguredConstant($node); |
|
48
|
|
|
} |
|
49
|
53 |
|
|
|
50
|
|
|
private function isConfiguredTrait(Node $node): bool |
|
51
|
|
|
{ |
|
52
|
77 |
|
return $node instanceof Trait_ && $this->config->trait; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
55 |
|
private function isConfiguredInterface(Node $node): bool |
|
56
|
|
|
{ |
|
57
|
55 |
|
return $node instanceof Interface_ && $this->config->interface; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
private function isConfiguredEnum(Node $node): bool |
|
61
|
|
|
{ |
|
62
|
|
|
return $node instanceof Enum_ && $this->config->enum; |
|
63
|
|
|
} |
|
64
|
55 |
|
|
|
65
|
25 |
|
private function isConfiguredProperty(Node $node): bool |
|
66
|
|
|
{ |
|
67
|
25 |
|
return $node instanceof Property && $this->config->property; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
30 |
|
private function isConfiguredConstant(Node $node): bool |
|
71
|
6 |
|
{ |
|
72
|
|
|
return $node instanceof ClassConst && $this->config->constant; |
|
73
|
6 |
|
} |
|
74
|
|
|
|
|
75
|
|
|
private function isMethodOrFunction(Node $node): bool |
|
76
|
24 |
|
{ |
|
77
|
|
|
return ($node instanceof ClassMethod || $node instanceof Function_) && $this->config->function; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|