GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Sequence::validate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 2
dl 0
loc 16
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Marcosh\PhpValidationDSL\Combinator;
6
7
use InvalidArgumentException;
8
use Marcosh\PhpValidationDSL\Result\ValidationResult;
9
use Marcosh\PhpValidationDSL\Validation;
10
use Webmozart\Assert\Assert;
11
12
final class Sequence implements Validation
13
{
14
    /**
15
     * @var Validation[]
16
     */
17
    private $validations;
18
19
    /**
20
     * Sequence constructor.
21
     * @param Validation[] $validations
22
     * @throws InvalidArgumentException
23
     */
24
    private function __construct(array $validations)
25
    {
26
        Assert::allIsInstanceOf($validations, Validation::class);
27
28
        $this->validations = $validations;
29
    }
30
31
    /**
32
     * @param Validation[] $validations
33
     * @return self
34
     * @throws InvalidArgumentException
35
     */
36
    public static function validations(array $validations): self
37
    {
38
        return new self($validations);
39
    }
40
41
    public function validate($data, array $context = []): ValidationResult
42
    {
43
        return array_reduce(
44
            $this->validations,
45
            function (ValidationResult $carry, Validation $validation) use ($context): ValidationResult {
46
                return $carry->process(
47
                    /** @psalm-suppress MissingClosureParamType */
48
                    function ($validData) use ($validation, $context): ValidationResult {
49
                        return $validation->validate($validData, $context);
50
                    },
51
                    function () use ($carry): ValidationResult {
52
                        return $carry;
53
                    }
54
                );
55
            },
56
            ValidationResult::valid($data)
57
        );
58
    }
59
}
60