These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Chubbyphp\Deserialization\Decoder; |
||
6 | |||
7 | use Chubbyphp\Deserialization\DeserializerRuntimeException; |
||
8 | |||
9 | final class JsonTypeDecoder implements TypeDecoderInterface |
||
10 | { |
||
11 | /** |
||
12 | * @return string |
||
13 | */ |
||
14 | 3 | public function getContentType(): string |
|
15 | { |
||
16 | 3 | return 'application/json'; |
|
17 | } |
||
18 | |||
19 | /** |
||
20 | * @param string $data |
||
21 | * |
||
22 | * @throws DeserializerRuntimeException |
||
23 | * |
||
24 | * @return array |
||
25 | */ |
||
26 | 4 | public function decode(string $data): array |
|
27 | { |
||
28 | 4 | $decoded = $json = json_decode($data, true); |
|
0 ignored issues
–
show
|
|||
29 | |||
30 | 4 | if (JSON_ERROR_NONE !== json_last_error()) { |
|
31 | 1 | throw DeserializerRuntimeException::createNotParsable($this->getContentType(), json_last_error_msg()); |
|
32 | } |
||
33 | |||
34 | 3 | if (!is_array($decoded)) { |
|
35 | 1 | throw DeserializerRuntimeException::createNotParsable($this->getContentType(), 'Not an object'); |
|
36 | } |
||
37 | |||
38 | 2 | return $decoded; |
|
39 | } |
||
40 | } |
||
41 |
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.