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

Each::assert()   B

Complexity

Conditions 5
Paths 7

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 9
cts 9
cp 1
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 9
nc 7
nop 1
crap 5
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\Helpers\CanValidateIterable;
18
use Respect\Validation\Validatable;
19
20
/**
21
 * Validates whether each value in the input is valid according to another rule.
22
 *
23
 * @author Alexandre Gomes Gaigalas <[email protected]>
24
 * @author Henrique Moody <[email protected]>
25
 * @author Nick Lombard <[email protected]>
26
 * @author William Espindola <[email protected]>
27
 */
28
final class Each extends AbstractRule
29
{
30
    use CanValidateIterable;
31
32
    /**
33
     * @var Validatable
34
     */
35
    private $rule;
36
37
    /**
38
     * Initializes the constructor.
39
     *
40
     * @param mixed $rule
41
     */
42 3
    public function __construct(Validatable $rule)
43
    {
44 3
        $this->rule = $rule;
45 3
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50 11
    public function assert($input): void
51
    {
52 11
        if (!$this->isIterable($input)) {
53 5
            throw $this->reportError($input);
54
        }
55
56 7
        foreach ($input as $value) {
57
            try {
58 6
                $this->rule->check($value);
59 2
            } catch (ValidationException $exception) {
60 6
                $exceptions[] = $exception;
61
            }
62
        }
63
64 7
        if (!empty($exceptions)) {
65 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

65
            throw $this->reportError($input)->/** @scrutinizer ignore-call */ setRelated($exceptions);
Loading history...
66
        }
67 5
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72 11
    public function validate($input): bool
73
    {
74
        try {
75 11
            $this->assert($input);
76 6
        } catch (ValidationException $exception) {
77 6
            return false;
78
        }
79
80 5
        return true;
81
    }
82
}
83