These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | /** |
||
6 | * This file is part of phpDocumentor. |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | * |
||
11 | * @link https://phpdoc.org |
||
12 | */ |
||
13 | |||
14 | namespace phpDocumentor\Descriptor\Builder\Reflector; |
||
15 | |||
16 | use phpDocumentor\Descriptor\Builder\AssemblerAbstract as BaseAssembler; |
||
17 | use phpDocumentor\Descriptor\Builder\AssemblerReducer; |
||
18 | use phpDocumentor\Descriptor\Builder\Reflector\Docblock\DescriptionAssemblerReducer; |
||
19 | use phpDocumentor\Descriptor\Collection; |
||
20 | use phpDocumentor\Descriptor\DescriptorAbstract; |
||
21 | use phpDocumentor\Descriptor\TagDescriptor; |
||
22 | use phpDocumentor\Reflection\DocBlock; |
||
23 | use phpDocumentor\Reflection\Type; |
||
24 | use phpDocumentor\Reflection\Types\Compound; |
||
25 | use function array_values; |
||
26 | use function count; |
||
27 | use function reset; |
||
28 | use function stripcslashes; |
||
29 | use function trim; |
||
30 | |||
31 | /** |
||
32 | * @template TDescriptor of \phpDocumentor\Descriptor\Descriptor |
||
33 | * @template TInput of object |
||
34 | * @extends BaseAssembler<TDescriptor, TInput> |
||
35 | */ |
||
36 | abstract class AssemblerAbstract extends BaseAssembler |
||
37 | { |
||
38 | /** @var AssemblerReducer[] */ |
||
39 | private $reducers; |
||
40 | |||
41 | public function __construct(AssemblerReducer ...$reducers) |
||
42 | { |
||
43 | $this->reducers = $reducers; |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * @param TInput $data |
||
48 | * |
||
49 | * @return TDescriptor|null |
||
50 | */ |
||
51 | 19 | public function create(object $data) |
|
52 | { |
||
53 | 19 | $descriptor = $this->buildDescriptor($data); |
|
54 | |||
55 | 19 | foreach ($this->reducers as $reducer) { |
|
56 | 17 | if ($reducer instanceof BaseAssembler) { |
|
57 | 17 | $reducer->setBuilder($this->getBuilder()); |
|
58 | } |
||
59 | |||
60 | 17 | $descriptor = $reducer->create($data, $descriptor); |
|
61 | } |
||
62 | |||
63 | 19 | return $descriptor; |
|
64 | } |
||
65 | |||
66 | /** |
||
67 | * @param TInput $data |
||
68 | * |
||
69 | * @return TDescriptor|null |
||
70 | */ |
||
71 | protected function buildDescriptor(object $data) |
||
72 | { |
||
73 | return null; |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | * Assemble DocBlock. |
||
78 | */ |
||
79 | protected function assembleDocBlock(?DocBlock $docBlock, DescriptorAbstract $target) : void |
||
80 | { |
||
81 | if (!$docBlock) { |
||
82 | return; |
||
83 | } |
||
84 | |||
85 | $target->setSummary($docBlock->getSummary()); |
||
86 | |||
87 | $reducer = new DescriptionAssemblerReducer(); |
||
88 | $reducer->setBuilder($this->getBuilder()); |
||
89 | $target = $reducer->create($docBlock, $target); |
||
0 ignored issues
–
show
|
|||
90 | |||
91 | foreach ($docBlock->getTags() as $tag) { |
||
92 | $tagDescriptor = $this->builder->buildDescriptor($tag, TagDescriptor::class); |
||
93 | |||
94 | // allow filtering of tags |
||
95 | if (!$tagDescriptor) { |
||
96 | continue; |
||
97 | } |
||
98 | |||
99 | $target->getTags() |
||
100 | ->fetch($tag->getName(), new Collection()) |
||
101 | ->add($tagDescriptor); |
||
102 | } |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * Extracts the package from the DocBlock. |
||
107 | */ |
||
108 | protected function extractPackageFromDocBlock(?DocBlock $docBlock) : ?string |
||
109 | { |
||
110 | $packageTags = $docBlock ? $docBlock->getTagsByName('package') : []; |
||
111 | if (count($packageTags) === 0) { |
||
112 | return null; |
||
113 | } |
||
114 | |||
115 | /** @var DocBlock\Tags\Generic $tag */ |
||
116 | $tag = reset($packageTags); |
||
117 | |||
118 | return trim((string) $tag->getDescription()); |
||
119 | } |
||
120 | |||
121 | /** |
||
122 | * @deprecated the functionality in this method has been moved to the Compound type in the latest unreleased |
||
123 | * version of the TypeResolver library |
||
124 | */ |
||
125 | 3 | public static function deduplicateTypes(?Type $type) : ?Type |
|
126 | { |
||
127 | 3 | if ($type instanceof Compound) { |
|
128 | 2 | $normalizedTypes = []; |
|
129 | |||
130 | 2 | foreach ($type as $typePart) { |
|
131 | 2 | $normalizedTypes[(string) $typePart] = $typePart; |
|
132 | } |
||
133 | |||
134 | 2 | return new Compound(array_values($normalizedTypes)); |
|
135 | } |
||
136 | |||
137 | 1 | return $type; |
|
138 | } |
||
139 | |||
140 | protected function pretifyValue(?string $value) : ?string |
||
141 | { |
||
142 | if ($value === null) { |
||
143 | return null; |
||
144 | } |
||
145 | |||
146 | return stripcslashes($value); |
||
147 | } |
||
148 | } |
||
149 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: