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