We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| 1 | <?php |
||
| 18 | class KeyValue extends AbstractRule |
||
| 19 | { |
||
| 20 | public $comparedKey; |
||
| 21 | public $ruleName; |
||
| 22 | public $baseKey; |
||
| 23 | |||
| 24 | 11 | public function __construct($comparedKey, $ruleName, $baseKey) |
|
| 30 | |||
| 31 | 10 | private function getRule($input) |
|
| 50 | |||
| 51 | private function overwriteExceptionParams(ValidationException $exception) |
||
| 52 | { |
||
| 53 | $params = []; |
||
| 54 | foreach ($exception->getParams() as $key => $value) { |
||
| 55 | if (in_array($key, ['template', 'translator'])) { |
||
| 56 | continue; |
||
| 57 | } |
||
| 58 | |||
| 59 | $params[$key] = $this->baseKey; |
||
| 60 | } |
||
| 61 | |||
| 62 | $exception->configure($this->comparedKey, $params); |
||
| 63 | |||
| 64 | return $exception; |
||
| 65 | } |
||
| 66 | |||
| 67 | 3 | public function assert($input) |
|
| 68 | { |
||
| 69 | 3 | $rule = $this->getRule($input); |
|
| 70 | |||
| 71 | try { |
||
| 72 | 2 | $rule->assert($input[$this->comparedKey]); |
|
| 73 | 1 | } catch (ValidationException $exception) { |
|
| 74 | throw $this->overwriteExceptionParams($exception); |
||
| 75 | } |
||
| 76 | |||
| 77 | 1 | return true; |
|
| 78 | } |
||
| 79 | |||
| 80 | 2 | public function check($input) |
|
| 81 | { |
||
| 82 | 2 | $rule = $this->getRule($input); |
|
| 83 | |||
| 84 | try { |
||
| 85 | 2 | $rule->check($input[$this->comparedKey]); |
|
| 86 | 1 | } catch (ValidationException $exception) { |
|
| 87 | throw $this->overwriteExceptionParams($exception); |
||
| 88 | } |
||
| 89 | |||
| 90 | 1 | return true; |
|
| 91 | } |
||
| 92 | |||
| 93 | 5 | public function validate($input) |
|
| 103 | } |
||
| 104 |