We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
1 | <?php |
||
17 | abstract class AbstractRelated extends AbstractRule |
||
18 | { |
||
19 | public $mandatory = true; |
||
20 | public $reference = ''; |
||
21 | public $validator; |
||
22 | |||
23 | abstract public function hasReference($input); |
||
24 | |||
25 | abstract public function getReferenceValue($input); |
||
26 | |||
27 | 12 | public function __construct($reference, Validatable $validator = null, $mandatory = true) |
|
28 | { |
||
29 | 12 | $this->setName($reference); |
|
30 | 12 | if ($validator && !$validator->getName()) { |
|
31 | 7 | $validator->setName($reference); |
|
32 | } |
||
33 | |||
34 | 12 | $this->reference = $reference; |
|
35 | 12 | $this->validator = $validator; |
|
36 | 12 | $this->mandatory = $mandatory; |
|
37 | 12 | } |
|
38 | |||
39 | 5 | public function setName($name) |
|
40 | { |
||
41 | 5 | parent::setName($name); |
|
42 | |||
43 | 5 | if ($this->validator instanceof Validatable) { |
|
44 | $this->validator->setName($name); |
||
45 | } |
||
46 | |||
47 | 5 | return $this; |
|
48 | } |
||
49 | |||
50 | 3 | private function decision($type, $hasReference, $input) |
|
56 | |||
57 | 1 | public function assert($input) |
|
58 | { |
||
59 | 1 | $hasReference = $this->hasReference($input); |
|
60 | 1 | if ($this->mandatory && !$hasReference) { |
|
61 | throw $this->reportError($input, ['hasReference' => false]); |
||
62 | } |
||
63 | |||
64 | try { |
||
65 | 1 | return $this->decision('assert', $hasReference, $input); |
|
66 | } catch (ValidationException $e) { |
||
67 | throw $this |
||
68 | ->reportError($this->reference, ['hasReference' => true]) |
||
69 | ->addRelated($e); |
||
70 | } |
||
71 | } |
||
72 | |||
73 | 1 | public function check($input) |
|
82 | |||
83 | 2 | public function validate($input) |
|
92 | } |
||
93 |