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 (#1034)
by Henrique
04:43 queued 02:30
created

Each::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
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
        $exceptions = [];
57 7
        foreach ($input as $value) {
58
            try {
59 6
                $this->rule->check($value);
60 2
            } catch (ValidationException $exception) {
61 6
                $exceptions[] = $exception;
62
            }
63
        }
64
65 7
        if (!empty($exceptions)) {
66 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

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