We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Complex classes like NestedValidationException often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use NestedValidationException, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
18 | class NestedValidationException extends ValidationException implements IteratorAggregate |
||
19 | { |
||
20 | /** |
||
21 | * @var SplObjectStorage |
||
22 | */ |
||
23 | private $exceptions = []; |
||
24 | |||
25 | /** |
||
26 | * @param ValidationException $exception |
||
27 | * |
||
28 | * @return self |
||
29 | */ |
||
30 | 3 | public function addRelated(ValidationException $exception) |
|
36 | |||
37 | /** |
||
38 | * @param string $path |
||
39 | * @param ValidationException $exception |
||
40 | * |
||
41 | * @return ValidationException |
||
42 | */ |
||
43 | private function getExceptionForPath($path, ValidationException $exception) |
||
59 | |||
60 | /** |
||
61 | * @param array $paths |
||
62 | * |
||
63 | * @return array |
||
64 | */ |
||
65 | public function findMessages(array $paths) |
||
94 | |||
95 | /** |
||
96 | * @return Exception |
||
97 | */ |
||
98 | 1 | public function findRelated($path) |
|
110 | |||
111 | /** |
||
112 | * @return RecursiveIteratorIterator |
||
113 | */ |
||
114 | 1 | private function getRecursiveIterator() |
|
124 | |||
125 | private function isSkippable(ValidationException $exception) |
||
131 | |||
132 | /** |
||
133 | * @return SplObjectStorage |
||
134 | */ |
||
135 | public function getIterator() |
||
179 | |||
180 | /** |
||
181 | * @return array |
||
182 | */ |
||
183 | public function getMessages() |
||
196 | |||
197 | /** |
||
198 | * @return string |
||
199 | */ |
||
200 | public function getFullMessage() |
||
221 | |||
222 | /** |
||
223 | * @return SplObjectStorage |
||
224 | */ |
||
225 | 3 | public function getRelated() |
|
233 | |||
234 | /** |
||
235 | * @param string $name |
||
236 | * @param mixed $value |
||
237 | * |
||
238 | * @return self |
||
239 | */ |
||
240 | public function setParam($name, $value) |
||
252 | |||
253 | /** |
||
254 | * @return bool |
||
255 | */ |
||
256 | 1 | private function isRelated($name, ValidationException $exception) |
|
260 | |||
261 | /** |
||
262 | * @return ValidationException |
||
263 | */ |
||
264 | 1 | public function getRelatedByName($name) |
|
276 | |||
277 | /** |
||
278 | * @param array $exceptions |
||
279 | * |
||
280 | * @return self |
||
281 | */ |
||
282 | public function setRelated(array $exceptions) |
||
290 | } |
||
291 |
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.