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\Members; |
9
|
|
|
|
10
|
|
|
use PhpParser\Node; |
|
|
|
|
11
|
|
|
use PhpParser\Node\Stmt\Property; |
|
|
|
|
12
|
|
|
use PhUml\Code\Attributes\Attribute; |
13
|
|
|
use PhUml\Code\Variables\Variable; |
14
|
|
|
use PhUml\Parser\Code\Builders\Filters\PrivateVisibilityFilter; |
15
|
|
|
use PhUml\Parser\Code\Builders\Filters\ProtectedVisibilityFilter; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* It builds an array of `Attributes` for a `ClassDefinition` or a `TraitDefinition` |
19
|
|
|
* |
20
|
|
|
* It applies one or more `VisibilityFilter`s |
21
|
|
|
* |
22
|
|
|
* @see PrivateVisibilityFilter |
23
|
|
|
* @see ProtectedVisibilityFilter |
24
|
|
|
*/ |
25
|
|
|
final class FilteredAttributesBuilder implements AttributesBuilder |
26
|
|
|
{ |
27
|
|
|
public function __construct( |
28
|
|
|
private VisibilityBuilder $visibilityBuilder, |
29
|
|
|
private TypeBuilder $typeBuilder, |
30
|
|
|
private VisibilityFilters $visibilityFilters |
31
|
|
|
) { |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param Node[] $parsedAttributes |
36
|
|
|
* @return Attribute[] |
37
|
|
|
*/ |
38
|
|
|
public function build(array $parsedAttributes): array |
39
|
|
|
{ |
40
|
|
|
$attributes = array_filter($parsedAttributes, static fn ($attribute): bool => $attribute instanceof Property); |
41
|
|
|
|
42
|
|
|
return array_map(function (Property $attribute): Attribute { |
43
|
|
|
$variable = new Variable( |
44
|
|
|
"\${$attribute->props[0]->name}", |
45
|
|
|
$this->typeBuilder->fromAttributeType($attribute->type, $attribute->getDocComment()) |
46
|
|
|
); |
47
|
|
|
$visibility = $this->visibilityBuilder->build($attribute); |
48
|
|
|
|
49
|
|
|
return new Attribute($variable, $visibility, $attribute->isStatic()); |
50
|
|
|
}, $this->visibilityFilters->apply($attributes)); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param Node\Param[] $constructorParameters |
55
|
|
|
* @return Attribute[] |
56
|
|
|
*/ |
57
|
|
|
public function fromPromotedProperties(array $constructorParameters): array |
58
|
|
|
{ |
59
|
|
|
$promotedProperties = array_filter($constructorParameters, fn (Node\Param $param) => $param->flags !== 0); |
|
|
|
|
60
|
|
|
|
61
|
|
|
return array_map(function (Node\Param $param): Attribute { |
62
|
|
|
/** @var Node\Expr\Variable $var */ |
63
|
|
|
$var = $param->var; |
64
|
|
|
|
65
|
|
|
/** @var string $name */ |
66
|
|
|
$name = $var->name; |
67
|
|
|
|
68
|
|
|
$type = $this->typeBuilder->fromMethodParameter($param->type, $param->getDocComment(), $name); |
69
|
|
|
$visibility = $this->visibilityBuilder->fromFlags($param->flags); |
70
|
|
|
|
71
|
|
|
return new Attribute(new Variable("\$${name}", $type), $visibility); |
72
|
|
|
}, $promotedProperties); |
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