RequestValidator::validate()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 9
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 12
ccs 9
cts 9
cp 1
crap 4
rs 9.9666
1
<?php
2
3
namespace CHStudio\Raven\Bridge\LeagueOpenAPIValidation;
4
5
use CHStudio\Raven\Bridge\LeagueOpenAPIValidation\Exception\ValidationExceptionMapper;
6
use CHStudio\Raven\Validator\Exception\OperationNotFoundException;
7
use CHStudio\Raven\Validator\RequestValidatorInterface;
8
use League\OpenAPIValidation\PSR7\Exception\MultipleOperationsMismatchForRequest;
9
use League\OpenAPIValidation\PSR7\Exception\NoOperation;
10
use League\OpenAPIValidation\PSR7\Exception\NoPath;
11
use League\OpenAPIValidation\PSR7\RequestValidator as LeagueRequestValidator;
12
use Psr\Http\Message\RequestInterface;
13
14
class RequestValidator implements RequestValidatorInterface
15
{
16 10
    public function __construct(
17
        private readonly LeagueRequestValidator $adapted,
18
        private readonly ValidationExceptionMapper $mapper
19
    ) {
20 10
    }
21
22 6
    public function validate(RequestInterface $input): void
23
    {
24
        try {
25 6
            $this->adapted->validate($input);
26 5
        } catch (NoOperation|NoPath|MultipleOperationsMismatchForRequest $e) {
27 3
            throw new OperationNotFoundException($input, $e);
28 2
        } catch (\Throwable $e) {
29 2
            $error = $this->mapper->map($e);
30 2
            if ($error !== null) {
31 1
                throw $error;
32
            }
33 1
            throw $e;
34
        }
35
    }
36
}
37