1 | <?php declare(strict_types=1); |
||
26 | class ExtractorDefinitionBuilder implements ExtractorDefinitionBuilderInterface |
||
27 | { |
||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $type_regexp = '/ |
||
32 | ^ |
||
33 | ( |
||
34 | (?<name> |
||
35 | [-_\w]* |
||
36 | ) |
||
37 | (?: |
||
38 | \s* |
||
39 | (?<group> |
||
40 | \( |
||
41 | \s* |
||
42 | (?<param> |
||
43 | (?-4)* |
||
44 | | |
||
45 | [\w\\\\]+ |
||
46 | ) |
||
47 | \s* |
||
48 | \) |
||
49 | ) |
||
50 | )? |
||
51 | (?: |
||
52 | \s* |
||
53 | (?<arr>(?:\s*\[\s*\]\s*)+) |
||
54 | )? |
||
55 | (?: |
||
56 | \s* |
||
57 | \| |
||
58 | \s* |
||
59 | (?<alt>(?-6)) |
||
60 | )? |
||
61 | ) |
||
62 | $ |
||
63 | /xi'; |
||
64 | |||
65 | /** |
||
66 | * {@inheritdoc} |
||
67 | */ |
||
68 | 20 | public function build(string $definition): ExtractorDefinitionInterface |
|
89 | |||
90 | /** |
||
91 | * @param string $name |
||
92 | * @param null|string $param |
||
93 | * @param null|string $alt_definitions |
||
94 | * @param int $depth |
||
95 | * @param bool $groups |
||
96 | * |
||
97 | * @return null|ExtractorDefinitionInterface |
||
98 | * @throws ExtractorDefinitionBuilderException |
||
99 | */ |
||
100 | 18 | protected function buildExtractor(string $name, string $param, string $alt_definitions, int $depth, bool $groups): ExtractorDefinitionInterface |
|
128 | |||
129 | /** |
||
130 | * @param PlainExtractorDefinitionInterface $definition |
||
131 | * @param string $alt_definitions |
||
132 | * |
||
133 | * @return VariableExtractorDefinition |
||
134 | * @throws ExtractorDefinitionBuilderException |
||
135 | */ |
||
136 | 6 | protected function buildVariableDefinition(PlainExtractorDefinitionInterface $definition, string $alt_definitions): VariableExtractorDefinition |
|
155 | |||
156 | /** |
||
157 | * @param null|ExtractorDefinitionInterface $definition |
||
158 | * @param int $depth |
||
159 | * @param bool $groups |
||
160 | * |
||
161 | * @return ExtractorDefinitionInterface |
||
162 | * @throws ExtractorDefinitionBuilderException |
||
163 | */ |
||
164 | 6 | protected function buildArrayDefinition(?ExtractorDefinitionInterface $definition, int $depth, bool $groups): ExtractorDefinitionInterface |
|
183 | |||
184 | 18 | private function getDepth(array $matches): int |
|
192 | |||
193 | 18 | private function hasGroups(array $matches): bool |
|
197 | |||
198 | 15 | private function buildPlainExtractor(string $name, ?ExtractorDefinitionInterface $next = null): PlainExtractorDefinitionInterface |
|
206 | } |
||
207 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.