1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/** |
3
|
|
|
* PHP version 8.0 |
4
|
|
|
* |
5
|
|
|
* This source file is subject to the license that is bundled with this package in the file LICENSE. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace PhUml\Parser\Code\Builders; |
9
|
|
|
|
10
|
|
|
use PhpParser\Node; |
|
|
|
|
11
|
|
|
use PhpParser\Node\Stmt\ClassConst; |
|
|
|
|
12
|
|
|
use PhpParser\Node\Stmt\ClassMethod; |
|
|
|
|
13
|
|
|
use PhpParser\Node\Stmt\Property; |
|
|
|
|
14
|
|
|
use PhUml\Code\Attributes\Attribute; |
15
|
|
|
use PhUml\Code\Attributes\Constant; |
16
|
|
|
use PhUml\Code\Methods\Method; |
17
|
|
|
use PhUml\Code\UseStatements; |
18
|
|
|
use PhUml\Parser\Code\Builders\Members\AttributesBuilder; |
19
|
|
|
use PhUml\Parser\Code\Builders\Members\ConstantsBuilder; |
20
|
|
|
use PhUml\Parser\Code\Builders\Members\MethodsBuilder; |
21
|
|
|
use PhUml\Parser\Code\Builders\Members\VisibilityFilters; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* It builds the constants, attributes and methods of a definition |
25
|
|
|
* |
26
|
|
|
* @see ConstantsBuilder for more details about the constants creation |
27
|
|
|
* @see AttributesBuilder for more details about the attributes creation |
28
|
|
|
* @see MethodsBuilder for more details about the methods creation |
29
|
|
|
*/ |
30
|
|
|
final class MembersBuilder |
31
|
|
|
{ |
32
|
|
|
public function __construct( |
33
|
|
|
private ConstantsBuilder $constantsBuilder, |
34
|
|
|
private AttributesBuilder $attributesBuilder, |
35
|
|
|
private MethodsBuilder $methodsBuilder, |
36
|
|
|
private VisibilityFilters $filters, |
37
|
|
|
) { |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param Node[] $members |
42
|
|
|
* @return Constant[] |
43
|
|
|
*/ |
44
|
|
|
public function constants(array $members): array |
45
|
|
|
{ |
46
|
|
|
/** @var ClassConst[] $constants */ |
47
|
|
|
$constants = array_filter($members, static fn ($attribute): bool => $attribute instanceof ClassConst); |
48
|
|
|
|
49
|
|
|
/** @var ClassConst[] $filteredConstants */ |
50
|
|
|
$filteredConstants = $this->filters->apply($constants); |
51
|
|
|
|
52
|
|
|
return $this->constantsBuilder->build($filteredConstants); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param Node[] $members |
57
|
|
|
* @return Attribute[] |
58
|
|
|
*/ |
59
|
|
|
public function attributes(array $members, ?ClassMethod $constructor, UseStatements $useStatements): array |
60
|
|
|
{ |
61
|
|
|
$attributes = []; |
62
|
|
|
if ($constructor !== null) { |
63
|
|
|
$attributes = $this->attributesFromPromotedProperties($constructor, $useStatements); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** @var Property[] $properties */ |
67
|
|
|
$properties = array_filter($members, static fn ($attribute): bool => $attribute instanceof Property); |
68
|
|
|
|
69
|
|
|
/** @var Property[] $filteredAttributes */ |
70
|
|
|
$filteredAttributes = $this->filters->apply($properties); |
71
|
|
|
|
72
|
|
|
return array_merge($this->attributesBuilder->build($filteredAttributes, $useStatements), $attributes); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param ClassMethod[] $methods |
77
|
|
|
* @return Method[] |
78
|
|
|
*/ |
79
|
|
|
public function methods(array $methods, UseStatements $useStatements): array |
80
|
|
|
{ |
81
|
|
|
/** @var ClassMethod[] $filteredMethods */ |
82
|
|
|
$filteredMethods = $this->filters->apply($methods); |
83
|
|
|
|
84
|
|
|
return $this->methodsBuilder->build($filteredMethods, $useStatements); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** @return Attribute[] */ |
88
|
|
|
private function attributesFromPromotedProperties(ClassMethod $constructor, UseStatements $useStatements): array |
89
|
|
|
{ |
90
|
|
|
$promotedProperties = array_filter( |
91
|
|
|
$constructor->getParams(), |
92
|
|
|
static fn (Node\Param $param) => $param->flags !== 0 |
|
|
|
|
93
|
|
|
); |
94
|
|
|
|
95
|
|
|
/** @var Node\Param[] $filteredPromotedProperties */ |
96
|
|
|
$filteredPromotedProperties = $this->filters->apply($promotedProperties); |
97
|
|
|
|
98
|
|
|
return $this->attributesBuilder->fromPromotedProperties($filteredPromotedProperties, $useStatements); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
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