CompositeRequestValidator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 25
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A validate() 0 10 3
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
/**
20
 * Combines multiple request validators into a single request validator.
21
 * When a request validator returns an exception, all following request validators will not be called.
22
 *
23
 * @author Niels Nijens <[email protected]>
24
 */
25
final class CompositeRequestValidator implements ValidatorInterface
26
{
27
    /**
28
     * @var ValidatorInterface[]
29
     */
30
    private $validators;
31
32
    /**
33
     * @param ValidatorInterface[] $validators
34
     */
35
    public function __construct(iterable $validators)
36
    {
37
        $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...
38
    }
39
40
    public function validate(Request $request): ?RequestProblemExceptionInterface
41
    {
42
        foreach ($this->validators as $validator) {
43
            $exception = $validator->validate($request);
44
            if ($exception instanceof RequestProblemExceptionInterface) {
45
                return $exception;
46
            }
47
        }
48
49
        return null;
50
    }
51
}
52