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

Passed
Pull Request — master (#957)
by Henrique
02:30
created

Not::absorbAllOf()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4.432

Importance

Changes 0
Metric Value
cc 4
eloc 9
nc 4
nop 2
dl 0
loc 17
ccs 7
cts 10
cp 0.7
crap 4.432
rs 9.2
c 0
b 0
f 0
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
declare(strict_types=1);
13
14
namespace Respect\Validation\Rules;
15
16
use Respect\Validation\Exceptions\ValidationException;
17
use Respect\Validation\Validatable;
18
19
class Not extends AbstractRule
20
{
21
    public $rule;
22
23 10
    public function __construct(Validatable $rule)
24
    {
25 10
        $this->rule = $rule;
26 10
    }
27
28 5
    public function setName(string $name): Validatable
29
    {
30 5
        $this->rule->setName($name);
31
32 5
        return parent::setName($name);
33
    }
34
35 4
    public function validate($input): bool
36
    {
37 4
        return false === $this->rule->validate($input);
38
    }
39
40 4
    public function assert($input): void
41
    {
42 4
        if ($this->validate($input)) {
43
            return;
44
        }
45
46 4
        $rule = $this->rule;
47 4
        if ($rule instanceof AllOf) {
48 2
            $rule = $this->absorbAllOf($rule, $input);
49
        }
50
51 4
        $exception = $rule->reportError($input);
52 4
        $exception->updateMode(ValidationException::MODE_NEGATIVE);
53
54 4
        throw $exception;
55
    }
56
57 2
    private function absorbAllOf(AllOf $rule, $input)
58
    {
59 2
        $rules = $rule->getRules();
60 2
        while (($current = array_shift($rules))) {
61 2
            $rule = $current;
62 2
            if (!$rule instanceof AllOf) {
63 2
                continue;
64
            }
65
66
            if (!$rule->validate($input)) {
67
                continue;
68
            }
69
70
            $rules = $rule->getRules();
71
        }
72
73 2
        return $rule;
74
    }
75
}
76