Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Pull Request — master (#854)
by
unknown
11:50
created

AbstractComposite::removeRules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * This file is part of Respect/Validation.
5
 *
6
 * (c) Alexandre Gomes Gaigalas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the "LICENSE.md"
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Respect\Validation\Rules;
13
14
use Respect\Validation\Exceptions\ValidationException;
15
use Respect\Validation\Validatable;
16
use Respect\Validation\Validator;
17
18
abstract class AbstractComposite extends AbstractRule
19
{
20
    protected $rules = [];
21
22 16
    public function __construct(...$rule)
23
    {
24 16
        $this->addRules($rule);
25 16
    }
26
27 6
    public function setName($name)
28
    {
29 6
        $parentName = $this->getName();
30 6
        foreach ($this->rules as $rule) {
31 5
            $ruleName = $rule->getName();
32 5
            if ($ruleName && $parentName !== $ruleName) {
33 2
                continue;
34
            }
35
36 3
            $rule->setName($name);
37
        }
38
39 6
        return parent::setName($name);
40
    }
41
42
    public function setTemplate($template)
43
    {
44
        $parentTemplate = $this->getTemplate();
45
        foreach ($this->rules as $rule) {
46
            $ruleTemplate = $rule->getTemplate();
47
            if ($ruleTemplate && $parentTemplate !== $ruleTemplate) {
48
                continue;
49
            }
50
51
            $rule->setTemplate($template);
52
        }
53
54
        return parent::setTemplate($template);
55
    }
56
57 12
    public function addRule($validator, $arguments = [])
58
    {
59 12
        if (!$validator instanceof Validatable) {
60
            $this->appendRule(Validator::buildRule($validator, $arguments));
61
        } else {
62 12
            $this->appendRule($validator);
63
        }
64
65 12
        return $this;
66
    }
67
68 1
    public function removeRules()
69
    {
70 1
        $this->rules = [];
71 1
    }
72
73 16
    public function addRules(array $validators)
74
    {
75 16
        foreach ($validators as $key => $spec) {
76 1
            if ($spec instanceof Validatable) {
77 1
                $this->appendRule($spec);
78
            } elseif (is_numeric($key) && is_array($spec)) {
79
                $this->addRules($spec);
80
            } elseif (is_array($spec)) {
81
                $this->addRule($key, $spec);
82
            } else {
83 1
                $this->addRule($spec);
84
            }
85
        }
86
87 16
        return $this;
88
    }
89
90 3
    public function getRules()
91
    {
92 3
        return $this->rules;
93
    }
94
95 4
    public function hasRule($validator)
96
    {
97 4
        if (empty($this->rules)) {
98 1
            return false;
99
        }
100
101 3
        if ($validator instanceof Validatable) {
102 2
            return isset($this->rules[spl_object_hash($validator)]);
103
        }
104
105 1
        if (is_string($validator)) {
106 1
            foreach ($this->rules as $rule) {
107 1
                if (get_class($rule) == __NAMESPACE__.'\\'.$validator) {
108 1
                    return true;
109
                }
110
            }
111
        }
112
113 1
        return false;
114
    }
115
116 13
    protected function appendRule(Validatable $validator)
117
    {
118 13
        if (!$validator->getName() && $this->getName()) {
119 2
            $validator->setName($this->getName());
120
        }
121
122 13
        $this->rules[spl_object_hash($validator)] = $validator;
123 13
    }
124
125
    protected function validateRules($input)
126
    {
127
        $validators = $this->getRules();
128
        $exceptions = [];
129
        foreach ($validators as $v) {
130
            try {
131
                $v->assert($input);
132
            } catch (ValidationException $e) {
133
                $exceptions[] = $e;
134
            }
135
        }
136
137
        return $exceptions;
138
    }
139
}
140