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 (#766)
by Bradyn
03:43
created

OnlyOneOf::check()   C

Complexity

Conditions 7
Paths 11

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 8.4275

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 25
ccs 9
cts 13
cp 0.6923
rs 6.7272
cc 7
eloc 15
nc 11
nop 1
crap 8.4275
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
 */
19
class OnlyOneOf extends AbstractComposite
20
{
21 3
    public function assert($input)
22
    {
23 3
        $validators = $this->getRules();
24 3
        $exceptions = $this->validateRules($input);
25 3
        $numRules = count($validators);
26 3
        $numExceptions = count($exceptions);
27 3
        if ($numExceptions !== $numRules - 1) {
28 2
            throw $this->reportError($input)->setRelated($exceptions);
29
        }
30
31 1
        return true;
32
    }
33
34 4
    public function validate($input)
35
    {
36 4
        $onePassed = false;
37 4
        foreach ($this->getRules() as $v) {
38 4
            if ($v->validate($input)) {
39 2
                if (false === $onePassed) {
40 2
                    $onePassed = true;
41
                } else {
42 4
                    return false;
43
                }
44
            }
45
        }
46
47 3
        return $onePassed;
48
    }
49
50 1
    public function check($input)
51
    {
52 1
        $onePassed = false;
53 1
        foreach ($this->getRules() as $v) {
54
            try {
55 1
                if ($v->check($input)) {
56
                    if (false === $onePassed) {
57
                        $onePassed = true;
58
                    } else {
59
                        return false;
60
                    }
61
                }
62 1
            } catch (ValidationException $e) {
63 1
                if (!isset($firstException)) {
64 1
                    $firstException = $e;
65
                }
66
            }
67
        }
68
69 1
        if (isset($firstException)) {
70 1
            throw $firstException;
71
        }
72
73
        return $onePassed;
74
    }
75
}
76