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 (#787)
by Henrique
03:17
created

OneOf::assert()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 12
c 0
b 0
f 0
ccs 8
cts 8
cp 1
rs 9.4285
cc 2
eloc 8
nc 2
nop 1
crap 2
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
16
/**
17
 * @author Bradyn Poulsen <[email protected]>
18
 * @author Henrique Moody <[email protected]>
19
 */
20
class OneOf extends AbstractComposite
21
{
22 3
    public function assert($input)
23
    {
24 3
        $validators = $this->getRules();
25 3
        $exceptions = $this->validateRules($input);
26 3
        $numRules = count($validators);
27 3
        $numExceptions = count($exceptions);
28 3
        if ($numExceptions !== $numRules - 1) {
29 2
            throw $this->reportError($input)->setRelated($exceptions);
30
        }
31
32 1
        return true;
33
    }
34
35 7
    public function validate($input)
36
    {
37 7
        $rulesPassedCount = 0;
38 7
        foreach ($this->getRules() as $rule) {
39 6
            if (!$rule->validate($input)) {
40 5
                continue;
41
            }
42
43 4
            ++$rulesPassedCount;
44
        }
45
46 7
        return $rulesPassedCount === 1;
47
    }
48
49 5
    public function check($input)
50
    {
51 5
        $firstException = null;
52 5
        $rulesPassedCount = 0;
53 5
        foreach ($this->getRules() as $rule) {
54
            try {
55 4
                $rule->check($input);
56
57 3
                ++$rulesPassedCount;
58 3
            } catch (ValidationException $exception) {
59 4
                $firstException = $firstException ?: $exception;
60
            }
61
        }
62
63 5
        if ($rulesPassedCount === 1) {
64 1
            return true;
65
        }
66
67 4
        throw $firstException ?: $this->reportError($input);
68
    }
69
}
70