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 (#910)
by Henrique
02:24
created

Each   A

Complexity

Total Complexity 21

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Test Coverage

Coverage 81.58%

Importance

Changes 0
Metric Value
wmc 21
c 0
b 0
f 0
dl 0
loc 76
ccs 31
cts 38
cp 0.8158
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B validate() 0 17 7
B check() 0 13 5
C assert() 0 28 8
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 Each extends IterableType
20
{
21
    public $itemValidator;
22
    public $keyValidator;
23
24 4
    public function __construct(Validatable $itemValidator = null, Validatable $keyValidator = null)
25
    {
26 4
        $this->itemValidator = $itemValidator;
27 4
        $this->keyValidator = $keyValidator;
28 4
    }
29
30 3
    public function assert($input): void
31
    {
32 3
        $exceptions = [];
33
34 3
        if (!parent::validate($input)) {
35 1
            throw $this->reportError($input);
36
        }
37
38 2
        foreach ($input as $key => $item) {
39 2
            if (isset($this->itemValidator)) {
40
                try {
41 1
                    $this->itemValidator->assert($item);
42 1
                } catch (ValidationException $e) {
43 1
                    $exceptions[] = $e;
44
                }
45
            }
46
47 2
            if (isset($this->keyValidator)) {
48
                try {
49 1
                    $this->keyValidator->assert($key);
50 1
                } catch (ValidationException $e) {
51 2
                    $exceptions[] = $e;
52
                }
53
            }
54
        }
55
56 2
        if (!empty($exceptions)) {
57 2
            throw $this->reportError($input)->setRelated($exceptions);
0 ignored issues
show
Bug introduced by
The method setRelated() does not exist on Respect\Validation\Exceptions\ValidationException. It seems like you code against a sub-type of Respect\Validation\Exceptions\ValidationException such as Respect\Validation\Excep...stedValidationException. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

57
            throw $this->reportError($input)->/** @scrutinizer ignore-call */ setRelated($exceptions);
Loading history...
58
        }
59
    }
60
61 1
    public function check($input): void
62
    {
63 1
        if (!parent::validate($input)) {
64 1
            throw $this->reportError($input);
65
        }
66
67
        foreach ($input as $key => $item) {
68
            if (isset($this->itemValidator)) {
69
                $this->itemValidator->check($item);
70
            }
71
72
            if (isset($this->keyValidator)) {
73
                $this->keyValidator->check($key);
74
            }
75
        }
76
    }
77
78 11
    public function validate($input): bool
79
    {
80 11
        if (!parent::validate($input)) {
81 4
            return false;
82
        }
83
84 7
        foreach ($input as $key => $item) {
85 7
            if (isset($this->itemValidator) && !$this->itemValidator->validate($item)) {
86 1
                return false;
87
            }
88
89 6
            if (isset($this->keyValidator) && !$this->keyValidator->validate($key)) {
90 6
                return false;
91
            }
92
        }
93
94 5
        return true;
95
    }
96
}
97