Completed
Push — master ( 993520...f97157 )
by Dawid
06:13
created

AbstractCheckSchemaSubscriber   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 28
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validateSchema() 0 13 2
getSchemaValidatorFactory() 0 1 ?
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiechu\SymfonyCommonsBundle\EventListener;
6
7
use Spiechu\SymfonyCommonsBundle\Event\ResponseSchemaCheck\CheckRequest;
8
use Spiechu\SymfonyCommonsBundle\Service\SchemaValidator\SchemaValidatorFactoryInterface;
9
use Symfony\Component\Config\Exception\FileLocatorFileNotFoundException;
10
11
abstract class AbstractCheckSchemaSubscriber
12
{
13
    /**
14
     * @param CheckRequest $checkRequest
15
     *
16
     * @throws \RuntimeException
17
     * @throws \InvalidArgumentException
18
     * @throws FileLocatorFileNotFoundException
19
     */
20 2
    public function validateSchema(CheckRequest $checkRequest): void
21
    {
22 2
        $schemaLocation = $checkRequest->getResponseSchemaLocation();
23 2
        $schemaValidatorFactory = $this->getSchemaValidatorFactory();
24
25 2
        if (!$schemaValidatorFactory->hasSchema($schemaLocation)) {
26 2
            $schemaValidatorFactory->registerSchema($schemaLocation, $schemaLocation);
27
        }
28
29 2
        $schemaValidator = $schemaValidatorFactory->getValidator($schemaLocation);
30
31 2
        $checkRequest->setValidationResult($schemaValidator->validate($checkRequest->getContent()));
32 2
    }
33
34
    /**
35
     * @return SchemaValidatorFactoryInterface
36
     */
37
    abstract protected function getSchemaValidatorFactory(): SchemaValidatorFactoryInterface;
38
}
39