We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Complex classes like ValidationException 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 ValidationException, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 19 | class ValidationException extends InvalidArgumentException implements ExceptionInterface |
||
| 20 | { |
||
| 21 | const MODE_DEFAULT = 1; |
||
| 22 | const MODE_NEGATIVE = 2; |
||
| 23 | const STANDARD = 0; |
||
| 24 | public static $defaultTemplates = [ |
||
| 25 | self::MODE_DEFAULT => [ |
||
| 26 | self::STANDARD => 'Data validation failed for %s', |
||
| 27 | ], |
||
| 28 | self::MODE_NEGATIVE => [ |
||
| 29 | self::STANDARD => 'Data validation failed for %s', |
||
| 30 | ], |
||
| 31 | ]; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var int |
||
| 35 | */ |
||
| 36 | private static $maxDepthStringify = 5; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var int |
||
| 40 | */ |
||
| 41 | private static $maxCountStringify = 10; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var string |
||
| 45 | */ |
||
| 46 | private static $maxReplacementStringify = '...'; |
||
| 47 | |||
| 48 | protected $id = 'validation'; |
||
| 49 | protected $mode = self::MODE_DEFAULT; |
||
| 50 | protected $name = ''; |
||
| 51 | protected $template = ''; |
||
| 52 | protected $params = []; |
||
| 53 | private $customTemplate = false; |
||
| 54 | |||
| 55 | 8 | public static function format($template, array $vars = []) |
|
| 74 | |||
| 75 | /** |
||
| 76 | * @param mixed $value |
||
| 77 | * @param int $depth |
||
| 78 | * |
||
| 79 | * @return string |
||
| 80 | */ |
||
| 81 | 36 | public static function stringify($value, $depth = 1) |
|
| 111 | |||
| 112 | /** |
||
| 113 | * @param array $value |
||
| 114 | * @param int $depth |
||
| 115 | * |
||
| 116 | * @return string |
||
| 117 | */ |
||
| 118 | 20 | public static function stringifyArray(array $value, $depth = 1) |
|
| 151 | |||
| 152 | /** |
||
| 153 | * @param mixed $value |
||
| 154 | * @param int $depth |
||
| 155 | * |
||
| 156 | * @return string |
||
| 157 | */ |
||
| 158 | 9 | public static function stringifyObject($value, $depth = 2) |
|
| 190 | |||
| 191 | 2 | public function __toString() |
|
| 195 | |||
| 196 | 4 | public function chooseTemplate() |
|
| 200 | |||
| 201 | 3 | public function configure($name, array $params = []) |
|
| 209 | |||
| 210 | 5 | public function getName() |
|
| 214 | |||
| 215 | 1 | public function getId() |
|
| 219 | |||
| 220 | 5 | public function getMainMessage() |
|
| 231 | |||
| 232 | 1 | public function getParam($name) |
|
| 236 | |||
| 237 | 5 | public function getParams() |
|
| 241 | |||
| 242 | 5 | public function getTemplate() |
|
| 250 | |||
| 251 | 1 | public function hasParam($name) |
|
| 255 | |||
| 256 | 3 | public function setId($id) |
|
| 262 | |||
| 263 | 3 | public function setName($name) |
|
| 269 | |||
| 270 | public function setMode($mode) |
||
| 279 | |||
| 280 | public function setParam($key, $value) |
||
| 288 | |||
| 289 | 3 | public function setParams(array $params) |
|
| 299 | |||
| 300 | public function hasCustomTemplate() |
||
| 304 | |||
| 305 | 2 | public function setTemplate($template) |
|
| 317 | |||
| 318 | 3 | private function buildMessage() |
|
| 322 | |||
| 323 | 5 | protected function buildTemplate() |
|
| 329 | |||
| 330 | 3 | public function guessId() |
|
| 343 | } |
||
| 344 |