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 | protected $type_regexp2 = '/ |
||
65 | ^ |
||
66 | (?:((\w+\b(?:\(.*\))?(?:\s*\[\s*\])?)(?:\s*\|\s*(?-1))*)) |
||
67 | | |
||
68 | (?:\(\s*(?-2)\s*\)(?:\s*\[\s*\])?) |
||
69 | | |
||
70 | (\[\s*\]) |
||
71 | $ |
||
72 | /xi'; |
||
73 | |||
74 | /** |
||
75 | * {@inheritdoc} |
||
76 | */ |
||
77 | 19 | public function build(string $definition): ExtractorDefinitionInterface |
|
98 | |||
99 | /** |
||
100 | * @param string $name |
||
101 | * @param null|string $param |
||
102 | * @param null|string $alt_definitions |
||
103 | * @param int $depth |
||
104 | * @param bool $groups |
||
105 | * |
||
106 | * @return ExtractorDefinitionInterface |
||
107 | * @throws ExtractorDefinitionBuilderException |
||
108 | */ |
||
109 | 17 | protected function buildExtractor(string $name, string $param, string $alt_definitions, int $depth, bool $groups): ExtractorDefinitionInterface |
|
137 | |||
138 | /** |
||
139 | * @param PlainExtractorDefinitionInterface $definition |
||
140 | * @param string $alt_definitions |
||
141 | * |
||
142 | * @return VariableExtractorDefinition |
||
143 | * @throws ExtractorDefinitionBuilderException |
||
144 | */ |
||
145 | 6 | protected function buildVariableDefinition(PlainExtractorDefinitionInterface $definition, string $alt_definitions): VariableExtractorDefinition |
|
164 | |||
165 | /** |
||
166 | * @param null|ExtractorDefinitionInterface $definition |
||
167 | * @param int $depth |
||
168 | * @param bool $groups |
||
169 | * |
||
170 | * @return ExtractorDefinitionInterface |
||
171 | * @throws ExtractorDefinitionBuilderException |
||
172 | */ |
||
173 | 6 | protected function buildArrayDefinition(?ExtractorDefinitionInterface $definition, int $depth, bool $groups): ExtractorDefinitionInterface |
|
187 | |||
188 | /** |
||
189 | * @param array $matches |
||
190 | * |
||
191 | * @return int |
||
192 | */ |
||
193 | 17 | private function getDepth(array $matches): int |
|
201 | |||
202 | 17 | private function hasGroups(array $matches): bool |
|
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.