Passed
Pull Request — main (#71)
by Niels
02:12
created

CompositeRequestValidator::validate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 10
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the OpenapiBundle package.
7
 *
8
 * (c) Niels Nijens <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Nijens\OpenapiBundle\Validation\RequestValidator;
15
16
use Nijens\OpenapiBundle\ExceptionHandling\Exception\RequestProblemExceptionInterface;
17
use Symfony\Component\HttpFoundation\Request;
18
19
final class CompositeRequestValidator implements ValidatorInterface
20
{
21
    /**
22
     * @var ValidatorInterface[]
23
     */
24
    private $validators;
25
26
    /**
27
     * @param ValidatorInterface[] $validators
28
     */
29
    public function __construct(iterable $validators)
30
    {
31
        $this->validators = $validators;
0 ignored issues
show
Documentation Bug introduced by
It seems like $validators of type iterable is incompatible with the declared type Nijens\OpenapiBundle\Val...or\ValidatorInterface[] of property $validators.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
32
    }
33
34
    public function validate(Request $request): ?RequestProblemExceptionInterface
35
    {
36
        foreach ($this->validators as $validator) {
37
            $exception = $validator->validate($request);
38
            if ($exception instanceof RequestProblemExceptionInterface) {
39
                return $exception;
40
            }
41
        }
42
43
        return null;
44
    }
45
}
46