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\Comment\Doc; |
|
|
|
|
11
|
|
|
use PhpParser\Node\Identifier; |
|
|
|
|
12
|
|
|
use PhpParser\Node\Name; |
|
|
|
|
13
|
|
|
use PhpParser\Node\NullableType; |
|
|
|
|
14
|
|
|
use PhpParser\Node\UnionType; |
|
|
|
|
15
|
|
|
use PhUml\Code\UseStatements; |
16
|
|
|
use PhUml\Code\Variables\TypeDeclaration; |
17
|
|
|
use PhUml\Parser\Code\TypeResolver; |
18
|
|
|
|
19
|
|
|
final class TypeBuilder |
20
|
|
|
{ |
21
|
|
|
public function __construct(private TypeResolver $typeResolver) |
22
|
|
|
{ |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function fromMethodParameter( |
26
|
|
|
Identifier|Name|NullableType|UnionType|null $type, |
|
|
|
|
27
|
|
|
?Doc $docBlock, |
28
|
|
|
string $name, |
29
|
|
|
UseStatements $useStatements |
30
|
|
|
): TypeDeclaration { |
31
|
|
|
$methodComment = $docBlock?->getText(); |
32
|
|
|
if ($type === null) { |
33
|
|
|
return $this->typeResolver->resolveForParameter($methodComment, $name, $useStatements); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
$typeDeclaration = $this->fromParsedType($type); |
37
|
|
|
if (! $typeDeclaration->isBuiltInArray()) { |
38
|
|
|
return $typeDeclaration; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
$typeFromDocBlock = $this->typeResolver->resolveForParameter($methodComment, $name, $useStatements); |
42
|
|
|
|
43
|
|
|
return $typeFromDocBlock->isPresent() ? $typeFromDocBlock : $typeDeclaration; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function fromMethodReturnType( |
47
|
|
|
Identifier|Name|NullableType|UnionType|null $type, |
48
|
|
|
?Doc $docBlock, |
49
|
|
|
UseStatements $useStatements |
50
|
|
|
): TypeDeclaration { |
51
|
|
|
$methodComment = $docBlock?->getText(); |
52
|
|
|
if ($type === null) { |
53
|
|
|
return $this->typeResolver->resolveForReturn($methodComment, $useStatements); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$typeDeclaration = $this->fromParsedType($type); |
57
|
|
|
if (! $typeDeclaration->isBuiltInArray()) { |
58
|
|
|
return $typeDeclaration; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$typeFromDocBlock = $this->typeResolver->resolveForReturn($methodComment, $useStatements); |
62
|
|
|
|
63
|
|
|
return $typeFromDocBlock->isPresent() ? $typeFromDocBlock : $typeDeclaration; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function fromAttributeType( |
67
|
|
|
Identifier|Name|NullableType|UnionType|null $type, |
68
|
|
|
?Doc $docBlock, |
69
|
|
|
UseStatements $useStatements |
70
|
|
|
): TypeDeclaration { |
71
|
|
|
$attributeComment = $docBlock?->getText(); |
72
|
|
|
if ($type === null) { |
73
|
|
|
return $this->typeResolver->resolveForAttribute($attributeComment, $useStatements); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$typeDeclaration = $this->fromParsedType($type); |
77
|
|
|
if (! $typeDeclaration->isBuiltInArray()) { |
78
|
|
|
return $typeDeclaration; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
$typeFromDocBlock = $this->typeResolver->resolveForAttribute($attributeComment, $useStatements); |
82
|
|
|
|
83
|
|
|
return $typeFromDocBlock->isPresent() ? $typeFromDocBlock : $typeDeclaration; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
private function fromParsedType(Identifier|Name|NullableType|UnionType|null $type): TypeDeclaration |
87
|
|
|
{ |
88
|
|
|
return match (true) { |
89
|
|
|
$type instanceof NullableType => TypeDeclaration::fromNullable((string) $type->type), |
90
|
|
|
$type instanceof Name, $type instanceof Identifier => TypeDeclaration::from((string) $type), |
91
|
|
|
$type === null => TypeDeclaration::absent(), |
92
|
|
|
default => TypeDeclaration::fromUnionType($this->fromUnionType($type)), |
93
|
|
|
}; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** @return string[] */ |
97
|
|
|
private function fromUnionType(UnionType $type): array |
98
|
|
|
{ |
99
|
|
|
return array_map( |
100
|
|
|
static fn (Identifier|Name $name): string => (string) $name, |
101
|
|
|
$type->types |
102
|
|
|
); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
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