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

Validator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 35
ccs 10
cts 12
cp 0.8333
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A validate() 0 10 4
A getSchemaManager() 0 4 1
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