1 | <?php |
||
21 | final class CallDefinition implements CallDefinitionInterface |
||
22 | { |
||
23 | |||
24 | /** |
||
25 | * @var ContainerInterface |
||
26 | */ |
||
27 | private $container; |
||
28 | |||
29 | /** |
||
30 | * @var string|null |
||
31 | */ |
||
32 | private $objectReference; |
||
33 | |||
34 | /** |
||
35 | * @var string |
||
36 | */ |
||
37 | private $routineName; |
||
38 | |||
39 | /** |
||
40 | * @var array<MappingInterface> |
||
41 | */ |
||
42 | private $argumentMappings = array(); |
||
43 | |||
44 | /** |
||
45 | * @var bool |
||
46 | */ |
||
47 | private $isStaticCall; |
||
48 | |||
49 | 13 | public function __construct( |
|
69 | |||
70 | 1 | public function __sleep(): array |
|
79 | |||
80 | 7 | public function execute( |
|
81 | HydrationContextInterface $context, |
||
82 | array $dataFromAdditionalColumns |
||
83 | ) { |
||
84 | /** @var mixed $result */ |
||
85 | 7 | $result = null; |
|
|
|||
86 | |||
87 | /** @var null|object|string $callee */ |
||
88 | 7 | $callee = $this->resolveCallee((string)$this->objectReference, $context); |
|
89 | |||
90 | 7 | if ($this->isStaticCall && is_object($callee)) { |
|
91 | $callee = get_class($callee); |
||
92 | } |
||
93 | |||
94 | /** @var array<mixed> $arguments */ |
||
95 | 7 | $arguments = $this->resolveArguments( |
|
96 | 7 | $context, |
|
97 | $dataFromAdditionalColumns |
||
98 | ); |
||
99 | |||
100 | 7 | if (is_null($callee) && !empty($this->objectReference)) { |
|
101 | $result = null; |
||
102 | |||
103 | 7 | } elseif (is_null($callee)) { |
|
104 | 1 | $result = call_user_func_array($this->routineName, $arguments); |
|
105 | |||
106 | 6 | } elseif (is_string($callee)) { |
|
107 | 1 | $result = call_user_func_array("{$callee}::{$this->routineName}", $arguments); |
|
108 | |||
109 | } else { |
||
110 | 5 | $result = call_user_func_array([$callee, $this->routineName], $arguments); |
|
111 | } |
||
112 | |||
113 | 7 | return $result; |
|
114 | } |
||
115 | |||
116 | 1 | public function getObjectReference(): ?string |
|
120 | |||
121 | 1 | public function getRoutineName(): string |
|
125 | |||
126 | 1 | public function getArgumentMappings(): array |
|
130 | |||
131 | 1 | public function isStaticCall(): bool |
|
135 | |||
136 | /** |
||
137 | * (This return type should be nullable, but there seems to be a bug in current version psalm preventing it.) |
||
138 | * |
||
139 | * @return object|string|null |
||
140 | */ |
||
141 | 7 | private function resolveCallee( |
|
181 | |||
182 | /** |
||
183 | * @param array<scalar> $dataFromAdditionalColumns |
||
184 | * |
||
185 | * @return array<mixed> |
||
186 | */ |
||
187 | 7 | private function resolveArguments( |
|
188 | HydrationContextInterface $context, |
||
189 | array $dataFromAdditionalColumns |
||
190 | ): array { |
||
191 | /** @var array<mixed> $arguments */ |
||
192 | 7 | $arguments = array(); |
|
193 | |||
194 | 7 | if (isset($dataFromAdditionalColumns[''])) { |
|
195 | $arguments[] = $dataFromAdditionalColumns['']; |
||
196 | unset($dataFromAdditionalColumns['']); |
||
197 | } |
||
198 | |||
199 | 7 | foreach ($this->argumentMappings as $argumentMapping) { |
|
200 | /** @var MappingInterface $argumentMapping */ |
||
201 | |||
202 | 7 | $arguments[] = $argumentMapping->resolveValue( |
|
203 | 7 | $context, |
|
204 | $dataFromAdditionalColumns |
||
205 | ); |
||
206 | } |
||
207 | |||
208 | 7 | return $arguments; |
|
209 | } |
||
210 | |||
211 | 1 | public function wakeUpCall(ContainerInterface $container): void { |
|
214 | } |
||
215 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.