Completed
Push — master ( 215d99...92be6e )
by Tristan
10:33
created

Validator::validate()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 6
nc 3
nop 1
crap 4
1
<?php
2
3
namespace Nicofuma\SwaggerBundle\Validator;
4
5
use FR3D\SwaggerAssertions\PhpUnit\SymfonyAssertsTrait;
6
use FR3D\SwaggerAssertions\SchemaManager;
7
use Symfony\Component\HttpFoundation\Request;
8
9
class Validator
10
{
11
    use SymfonyAssertsTrait;
12
13
    /** @var SchemaManager */
14
    private $schemaManager;
15
16
    /** @var bool */
17
    private $strict;
18
19 4
    public function __construct(SchemaManager $schemaManager, $strict)
20
    {
21 4
        $this->schemaManager = $schemaManager;
22 4
        $this->strict = $strict;
23 4
    }
24
25 4
    public function validate(Request $request)
26
    {
27
        try {
28 4
            $this->assertRequestMatch($request, $this->schemaManager);
29 4
        } catch (\RuntimeException $e) {
30 3
            if ($this->strict || $e->getMessage() !== 'Request URI does not match with any swagger path definition') {
31 2
                throw $e;
32
            }
33
        }
34 2
    }
35
36
    /**
37
     * @return SchemaManager
38
     */
39
    public function getSchemaManager()
40
    {
41
        return $this->schemaManager;
42
    }
43
}
44