1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/** |
3
|
|
|
* PHP version 7.2 |
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\Const_; |
|
|
|
|
12
|
|
|
use PhpParser\Node\Expr\ConstFetch; |
|
|
|
|
13
|
|
|
use PhpParser\Node\Stmt\ClassConst; |
|
|
|
|
14
|
|
|
use PhUml\Code\Attributes\Constant; |
15
|
|
|
use PhUml\Code\Variables\TypeDeclaration; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* It builds an array of `Constants` for either a `ClassDefinition` or an `InterfaceDefinition` |
19
|
|
|
*/ |
20
|
|
|
final class FilteredConstantsBuilder implements ConstantsBuilder |
21
|
|
|
{ |
22
|
|
|
/** @var string[] */ |
23
|
|
|
private static $types = [ |
24
|
|
|
'integer' => 'int', |
25
|
|
|
'double' => 'float', |
26
|
|
|
'string' => 'string', |
27
|
|
|
]; |
28
|
|
|
|
29
|
|
|
/** @var VisibilityBuilder */ |
30
|
|
|
private $visibilityBuilder; |
31
|
|
|
|
32
|
|
|
/** @var VisibilityFilters */ |
33
|
|
|
private $visibilityFilters; |
34
|
|
|
|
35
|
|
|
public function __construct(VisibilityBuilder $visibilityBuilder, VisibilityFilters $filters) |
36
|
|
|
{ |
37
|
|
|
$this->visibilityBuilder = $visibilityBuilder; |
38
|
|
|
$this->visibilityFilters = $filters; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param Node[] $classAttributes |
43
|
|
|
* @return Constant[] |
44
|
|
|
*/ |
45
|
|
|
public function build(array $classAttributes): array |
46
|
|
|
{ |
47
|
|
|
$constants = array_filter($classAttributes, static function ($attribute): bool { |
48
|
|
|
return $attribute instanceof ClassConst; |
49
|
|
|
}); |
50
|
|
|
|
51
|
|
|
return array_map(function (ClassConst $constant): Constant { |
52
|
|
|
return new Constant( |
53
|
|
|
(string) $constant->consts[0]->name, |
54
|
|
|
TypeDeclaration::from($this->determineType($constant->consts[0])), |
55
|
|
|
$this->visibilityBuilder->build($constant) |
56
|
|
|
); |
57
|
|
|
}, $this->visibilityFilters->apply($constants)); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
private function determineType(Const_ $constant): ?string |
61
|
|
|
{ |
62
|
|
|
if (property_exists($constant->value, 'value')) { |
63
|
|
|
return self::$types[\gettype($constant->value->value)]; |
64
|
|
|
} |
65
|
|
|
if ($constant->value instanceof ConstFetch |
66
|
|
|
&& \in_array($constant->value->name->parts[0], ['true', 'false'], true)) { |
67
|
|
|
return 'bool'; |
68
|
|
|
} |
69
|
|
|
return null; // It's an expression |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
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