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 | 8 | [-_\w]* |
|
36 | ) |
||
37 | 8 | (?: |
|
38 | \s* |
||
39 | 8 | (?<group> |
|
40 | 1 | \( |
|
41 | \s* |
||
42 | (?<param> |
||
43 | 7 | (?-4)* |
|
44 | 6 | | |
|
45 | [\w\\\\]+ |
||
46 | ) |
||
47 | 1 | \s* |
|
48 | \) |
||
49 | ) |
||
50 | )? |
||
51 | (?: |
||
52 | \s* |
||
53 | (?<arr>(?:\s*\[\s*\]\s*)+) |
||
54 | )? |
||
55 | (?: |
||
56 | \s* |
||
57 | \| |
||
58 | 6 | \s* |
|
59 | (?<alt>(?-6)) |
||
60 | 6 | )? |
|
61 | ) |
||
62 | 6 | $ |
|
63 | 3 | /xi'; |
|
64 | |||
65 | /** |
||
66 | 6 | * {@inheritdoc} |
|
67 | */ |
||
68 | 6 | public function build(string $definition): ExtractorDefinitionInterface |
|
89 | |||
90 | 2 | /** |
|
91 | * @param string $name |
||
92 | * @param null|string $param |
||
93 | 2 | * @param null|string $alt_definitions |
|
94 | * @param int $depth |
||
95 | * @param bool $groups |
||
96 | * |
||
97 | * @return null|ExtractorDefinitionInterface |
||
98 | 2 | * @throws ExtractorDefinitionBuilderException |
|
99 | */ |
||
100 | 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 | 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 | protected function buildArrayDefinition(?ExtractorDefinitionInterface $definition, int $depth, bool $groups): ExtractorDefinitionInterface |
||
183 | |||
184 | private function getDepth(array $matches): int |
||
192 | |||
193 | private function hasGroups(array $matches): bool |
||
197 | |||
198 | 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.