We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| 1 | <?php |
||
| 21 | class ValidationException extends InvalidArgumentException implements ExceptionInterface |
||
| 22 | { |
||
| 23 | const MODE_DEFAULT = 1; |
||
| 24 | const MODE_NEGATIVE = 2; |
||
| 25 | const STANDARD = 0; |
||
| 26 | public static $defaultTemplates = [ |
||
| 27 | self::MODE_DEFAULT => [ |
||
| 28 | self::STANDARD => 'Data validation failed for %s', |
||
| 29 | ], |
||
| 30 | self::MODE_NEGATIVE => [ |
||
| 31 | self::STANDARD => 'Data validation failed for %s', |
||
| 32 | ], |
||
| 33 | ]; |
||
| 34 | |||
| 35 | protected $id = 'validation'; |
||
| 36 | protected $mode = self::MODE_DEFAULT; |
||
| 37 | protected $name = ''; |
||
| 38 | protected $template = ''; |
||
| 39 | protected $params = []; |
||
| 40 | private $customTemplate = false; |
||
| 41 | |||
| 42 | 8 | public static function format($template, array $vars = []) |
|
| 61 | |||
| 62 | /** |
||
| 63 | * @param mixed $value |
||
| 64 | * |
||
| 65 | * @return string |
||
| 66 | */ |
||
| 67 | 4 | public static function stringify($value) |
|
| 71 | |||
| 72 | 2 | public function __toString() |
|
| 76 | |||
| 77 | 4 | public function chooseTemplate() |
|
| 81 | |||
| 82 | 3 | public function configure($name, array $params = []) |
|
| 90 | |||
| 91 | 5 | public function getName() |
|
| 95 | |||
| 96 | protected function hasName(): bool |
||
| 97 | { |
||
| 98 | $name = $this->getName(); |
||
| 99 | if (is_numeric($name)) { |
||
| 100 | return (bool) (float) $name; |
||
| 101 | } |
||
| 102 | |||
| 103 | return !in_array($name, ['`FALSE`', '`NULL`', '`{ }`', '""', '']); |
||
| 104 | } |
||
| 105 | |||
| 106 | 1 | public function getId() |
|
| 110 | |||
| 111 | 5 | public function getMainMessage() |
|
| 112 | { |
||
| 113 | 5 | $vars = $this->getParams(); |
|
| 114 | 5 | $vars['name'] = $this->getName(); |
|
| 115 | 5 | $template = $this->getTemplate(); |
|
| 116 | 5 | if (isset($vars['translator']) && is_callable($vars['translator'])) { |
|
| 117 | $template = call_user_func($vars['translator'], $template); |
||
| 118 | } |
||
| 119 | |||
| 120 | 5 | return static::format($template, $vars); |
|
| 121 | } |
||
| 122 | |||
| 123 | 1 | public function getParam($name) |
|
| 127 | |||
| 128 | 5 | public function getParams() |
|
| 132 | |||
| 133 | 5 | public function getTemplate() |
|
| 141 | |||
| 142 | 1 | public function hasParam($name) |
|
| 146 | |||
| 147 | 3 | public function setId($id) |
|
| 153 | |||
| 154 | 3 | public function setName($name) |
|
| 160 | |||
| 161 | public function setMode($mode) |
||
| 162 | { |
||
| 163 | $this->mode = $mode; |
||
| 164 | $this->template = $this->buildTemplate(); |
||
| 165 | |||
| 166 | $this->buildMessage(); |
||
| 167 | |||
| 168 | return $this; |
||
| 169 | } |
||
| 170 | |||
| 171 | public function setParam($key, $value) |
||
| 172 | { |
||
| 173 | $this->params[$key] = $value; |
||
| 174 | |||
| 175 | $this->buildMessage(); |
||
| 176 | |||
| 177 | return $this; |
||
| 178 | } |
||
| 179 | |||
| 180 | 3 | public function setParams(array $params) |
|
| 190 | |||
| 191 | public function hasCustomTemplate() |
||
| 192 | { |
||
| 193 | return true === $this->customTemplate; |
||
| 194 | } |
||
| 195 | |||
| 196 | 2 | public function setTemplate($template) |
|
| 197 | { |
||
| 198 | 2 | $this->customTemplate = true; |
|
| 199 | 2 | if (isset(static::$defaultTemplates[$this->mode][$template])) { |
|
| 200 | $template = static::$defaultTemplates[$this->mode][$template]; |
||
| 201 | } |
||
| 202 | 2 | $this->template = $template; |
|
| 203 | |||
| 204 | 2 | $this->buildMessage(); |
|
| 205 | |||
| 206 | 2 | return $this; |
|
| 207 | } |
||
| 208 | |||
| 209 | 3 | private function buildMessage(): void |
|
| 213 | |||
| 214 | 5 | protected function buildTemplate() |
|
| 220 | |||
| 221 | 3 | public function guessId() |
|
| 222 | { |
||
| 223 | 3 | if (!empty($this->id) && 'validation' != $this->id) { |
|
| 224 | return $this->id; |
||
| 225 | } |
||
| 226 | |||
| 234 | } |
||
| 235 |