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

Validator::getSchemaManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
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