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 phpDocumentor\Reflection\DocBlock\Tags\InvalidTag; |
|
|
|
|
11
|
|
|
use phpDocumentor\Reflection\DocBlock\Tags\Param; |
|
|
|
|
12
|
|
|
use phpDocumentor\Reflection\DocBlock\Tags\TagWithType; |
|
|
|
|
13
|
|
|
use phpDocumentor\Reflection\DocBlockFactory; |
|
|
|
|
14
|
|
|
use phpDocumentor\Reflection\Type; |
|
|
|
|
15
|
|
|
use phpDocumentor\Reflection\Types\Compound; |
|
|
|
|
16
|
|
|
use phpDocumentor\Reflection\Types\Nullable; |
|
|
|
|
17
|
|
|
|
18
|
|
|
final class TagTypeFactory |
19
|
|
|
{ |
20
|
|
|
public function __construct(private DocBlockFactory $factory) |
21
|
|
|
{ |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function parameterTypeFrom(string $methodComment, string $parameterName): ?TagType |
25
|
|
|
{ |
26
|
|
|
$docBlock = $this->factory->create($methodComment); |
27
|
|
|
|
28
|
|
|
/** @var TagType[]|InvalidTag[] $parameterTags */ |
29
|
|
|
$parameterTags = $docBlock->getTagsByName('param'); |
30
|
|
|
|
31
|
|
|
/** @var Param[] $params */ |
32
|
|
|
$params = array_values(array_filter( |
33
|
|
|
$parameterTags, |
34
|
|
|
static fn (TagWithType|InvalidTag $parameter) => |
35
|
|
|
$parameter instanceof Param && "\${$parameter->getVariableName()}" === $parameterName |
36
|
|
|
)); |
37
|
|
|
|
38
|
|
|
if (count($params) < 1) { |
39
|
|
|
return null; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
[$param] = $params; |
43
|
|
|
|
44
|
|
|
return $this->resolveType($param->getType()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function returnTypeFrom(string $methodComment): ?TagType |
48
|
|
|
{ |
49
|
|
|
$docBlock = $this->factory->create($methodComment); |
50
|
|
|
|
51
|
|
|
/** @var TagWithType[]|InvalidTag[] $returnTags */ |
52
|
|
|
$returnTags = $docBlock->getTagsByName('return'); |
53
|
|
|
|
54
|
|
|
if (count($returnTags) < 1) { |
55
|
|
|
return null; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
[$return] = $returnTags; |
59
|
|
|
if ($return instanceof InvalidTag) { |
60
|
|
|
return null; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
return $this->resolveType($return->getType()); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function attributeTypeFrom(string $attributeComment): ?TagType |
67
|
|
|
{ |
68
|
|
|
$docBlock = $this->factory->create($attributeComment); |
69
|
|
|
|
70
|
|
|
/** @var TagWithType[]|InvalidTag[] $varTags */ |
71
|
|
|
$varTags = $docBlock->getTagsByName('var'); |
72
|
|
|
|
73
|
|
|
if (count($varTags) < 1) { |
74
|
|
|
return null; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
[$var] = $varTags; |
78
|
|
|
if ($var instanceof InvalidTag) { |
79
|
|
|
return null; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
return $this->resolveType($var->getType()); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
private function resolveType(?Type $type): ?TagType |
86
|
|
|
{ |
87
|
|
|
return match (true) { |
88
|
|
|
$type === null => null, |
89
|
|
|
$type instanceof Nullable => TagType::nullable((string) $type->getActualType()), |
|
|
|
|
90
|
|
|
$type instanceof Compound => TagType::compound(array_map('strval', $type->getIterator()->getArrayCopy())), |
91
|
|
|
default => TagType::named((string) $type) |
92
|
|
|
}; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
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