1 | <?php |
||
8 | abstract class AbstractNormalizableCommandResolverException extends \InvalidArgumentException implements NormalizableInterface |
||
9 | { |
||
10 | const SOURCE_RAW = null; |
||
11 | const SOURCE_ATTRIBUTE = 'pointer'; |
||
12 | const SOURCE_PARAMETER = 'parameter'; |
||
13 | |||
14 | /** @var string */ |
||
15 | private $propertyPath; |
||
16 | |||
17 | /** @var string|null */ |
||
18 | private $source; |
||
19 | |||
20 | /** |
||
21 | * @inheritDoc |
||
22 | */ |
||
23 | public function __construct(string $message, string $propertyPath = null, string $source = null) |
||
30 | |||
31 | /** |
||
32 | * From raw value directly injected |
||
33 | */ |
||
34 | public static function fromRaw(string $message, string $propertyPath = null): AbstractNormalizableCommandResolverException |
||
42 | |||
43 | /** |
||
44 | * From query string parameter ($_GET) |
||
45 | */ |
||
46 | public static function fromParameter(string $message, string $propertyPath = null): AbstractNormalizableCommandResolverException |
||
54 | |||
55 | /** |
||
56 | * From attribute parameter ($_POST) |
||
57 | */ |
||
58 | public static function fromAttribute(string $message, string $propertyPath = null): AbstractNormalizableCommandResolverException |
||
65 | |||
66 | public function getPropertyPath(): string |
||
70 | |||
71 | /** |
||
72 | * @return null|string |
||
73 | */ |
||
74 | public function getSource() |
||
78 | |||
79 | /** |
||
80 | * @inheritdoc |
||
81 | * Normalize the Exception into a ready to be JSON encoded array |
||
82 | * Example for Attribute $_POST: |
||
83 | * { |
||
84 | * "status": "406", |
||
85 | * "source": { "pointer": "/data/attributes/firstName" }, |
||
86 | * "title": "Invalid Attribute", |
||
87 | * "detail": "Array does not contain an element with key firstName" |
||
88 | * } |
||
89 | * |
||
90 | * Example for parameter $_GET |
||
91 | * { |
||
92 | * "status": "406", |
||
93 | * "source": { "parameter": "firstName" }, |
||
94 | * "title": "Invalid Query Parameter", |
||
95 | * "detail": "Array does not contain an element with key firstName" |
||
96 | * } |
||
97 | */ |
||
98 | public function normalize(): array |
||
110 | |||
111 | private function createSourceNode(string $propertyPath, string $source = null): array |
||
123 | |||
124 | private function createTitleNode(string $source = null): string |
||
136 | |||
137 | private static function cleanPropertyPath(string $propertyPath = null): string |
||
145 | } |
||
146 |
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.