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:21
created

OnlyOneOf   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 86.21%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 13
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 57
ccs 25
cts 29
cp 0.8621
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A assert() 0 12 2
A validate() 0 15 4
C check() 0 25 7
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