We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| 1 | <?php |
||
| 18 | abstract class AbstractComposite extends AbstractRule |
||
| 19 | { |
||
| 20 | protected $rules = []; |
||
| 21 | |||
| 22 | public function __construct(...$rule) |
||
| 23 | { |
||
| 24 | $this->addRules($rule); |
||
| 25 | } |
||
| 26 | |||
| 27 | public function setName($name) |
||
| 28 | { |
||
| 29 | $parentName = $this->getName(); |
||
| 30 | foreach ($this->rules as $rule) { |
||
| 31 | $ruleName = $rule->getName(); |
||
| 32 | if ($ruleName && $parentName !== $ruleName) { |
||
| 33 | continue; |
||
| 34 | } |
||
| 35 | |||
| 36 | $rule->setName($name); |
||
| 37 | } |
||
| 38 | |||
| 39 | return parent::setName($name); |
||
| 40 | } |
||
| 41 | |||
| 42 | public function addRule($validator, $arguments = []) |
||
| 43 | { |
||
| 44 | if (!$validator instanceof Validatable) { |
||
| 45 | $this->appendRule(Validator::buildRule($validator, $arguments)); |
||
| 46 | } else { |
||
| 47 | $this->appendRule($validator); |
||
| 48 | } |
||
| 49 | |||
| 50 | return $this; |
||
| 51 | } |
||
| 52 | |||
| 53 | public function removeRules() |
||
| 54 | { |
||
| 55 | $this->rules = []; |
||
| 56 | } |
||
| 57 | |||
| 58 | public function addRules(array $validators) |
||
| 59 | { |
||
| 60 | foreach ($validators as $key => $spec) { |
||
| 61 | if ($spec instanceof Validatable) { |
||
| 62 | $this->appendRule($spec); |
||
| 63 | } elseif (is_numeric($key) && is_array($spec)) { |
||
| 64 | $this->addRules($spec); |
||
| 65 | } elseif (is_array($spec)) { |
||
| 66 | $this->addRule($key, $spec); |
||
| 67 | } else { |
||
| 68 | $this->addRule($spec); |
||
| 69 | } |
||
| 70 | } |
||
| 71 | |||
| 72 | return $this; |
||
| 73 | } |
||
| 74 | |||
| 75 | public function getRules() |
||
| 76 | { |
||
| 77 | return $this->rules; |
||
| 78 | } |
||
| 79 | |||
| 80 | public function hasRule($validator) |
||
| 81 | { |
||
| 82 | if (empty($this->rules)) { |
||
| 83 | return false; |
||
| 84 | } |
||
| 85 | |||
| 86 | if ($validator instanceof Validatable) { |
||
| 87 | return isset($this->rules[spl_object_hash($validator)]); |
||
| 88 | } |
||
| 89 | |||
| 90 | if (is_string($validator)) { |
||
| 91 | foreach ($this->rules as $rule) { |
||
| 92 | if (get_class($rule) == __NAMESPACE__.'\\'.$validator) { |
||
| 93 | return true; |
||
| 94 | } |
||
| 95 | } |
||
| 96 | } |
||
| 97 | |||
| 98 | return false; |
||
| 99 | } |
||
| 100 | |||
| 101 | protected function appendRule(Validatable $validator) |
||
| 102 | { |
||
| 103 | if (!$validator->getName() && $this->getName()) { |
||
| 104 | $validator->setName($this->getName()); |
||
| 105 | } |
||
| 106 | |||
| 107 | $this->rules[spl_object_hash($validator)] = $validator; |
||
| 108 | } |
||
| 109 | |||
| 110 | protected function validateRules($input) |
||
| 124 | } |
||
| 125 |