1 | <?php declare(strict_types=1); |
||
25 | class ExtractorDefinitionBuilder implements ExtractorDefinitionBuilderInterface |
||
26 | { |
||
27 | /** |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $type_regexp = '/ |
||
31 | ^ |
||
32 | ( |
||
33 | (?<name> |
||
34 | [-_\w]* |
||
35 | ) |
||
36 | (?: |
||
37 | \s* |
||
38 | (?<group> |
||
39 | \( |
||
40 | \s* |
||
41 | (?<param> |
||
42 | (?-4)* |
||
43 | | |
||
44 | [\w\\\\]+ |
||
45 | ) |
||
46 | \s* |
||
47 | \) |
||
48 | ) |
||
49 | )? |
||
50 | (?: |
||
51 | \s* |
||
52 | (?<arr>(?:\s*\[\s*\]\s*)+) |
||
53 | )? |
||
54 | (?: |
||
55 | \s* |
||
56 | \| |
||
57 | \s* |
||
58 | (?<alt>(?-6)) |
||
59 | )? |
||
60 | ) |
||
61 | $ |
||
62 | /xi'; |
||
63 | |||
64 | /** |
||
65 | * {@inheritdoc} |
||
66 | */ |
||
67 | 20 | public function build(string $definition): ExtractorDefinitionInterface |
|
88 | |||
89 | /** |
||
90 | * @param string $name |
||
91 | * @param null|string $param |
||
92 | * @param null|string $alt_definitions |
||
93 | * @param int $depth |
||
94 | * @param bool $groups |
||
95 | * |
||
96 | * @return null|ExtractorDefinitionInterface |
||
97 | * @throws ExtractorDefinitionBuilderException |
||
98 | */ |
||
99 | 18 | protected function buildExtractor(string $name, string $param, string $alt_definitions, int $depth, bool $groups): ExtractorDefinitionInterface |
|
132 | |||
133 | /** |
||
134 | * @param PlainExtractorDefinitionInterface $definition |
||
135 | * @param string $alt_definitions |
||
136 | * |
||
137 | * @return VariableExtractorDefinition |
||
138 | * @throws ExtractorDefinitionBuilderException |
||
139 | */ |
||
140 | 6 | protected function buildVariableDefinition(PlainExtractorDefinitionInterface $definition, string $alt_definitions): VariableExtractorDefinition |
|
159 | |||
160 | /** |
||
161 | * @param null|ExtractorDefinitionInterface $definition |
||
162 | * @param int $depth |
||
163 | * @param bool $groups |
||
164 | * |
||
165 | * @return ExtractorDefinitionInterface |
||
166 | * @throws ExtractorDefinitionBuilderException |
||
167 | */ |
||
168 | 6 | protected function buildArrayDefinition(?ExtractorDefinitionInterface $definition, int $depth, bool $groups): ExtractorDefinitionInterface |
|
182 | |||
183 | /** |
||
184 | * @param array $matches |
||
185 | * |
||
186 | * @return int |
||
187 | */ |
||
188 | 18 | private function getDepth(array $matches): int |
|
196 | |||
197 | 18 | private function hasGroups(array $matches): bool |
|
201 | } |
||
202 |
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.