AbstractCheckSchemaSubscriber   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 27
ccs 8
cts 8
cp 1
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A validateSchema() 0 12 2
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 6
    public function validateSchema(CheckRequest $checkRequest): void
21
    {
22 6
        $schemaLocation = $checkRequest->getResponseSchemaLocation();
23 6
        $schemaValidatorFactory = $this->getSchemaValidatorFactory();
24
25 6
        if (!$schemaValidatorFactory->hasSchema($schemaLocation)) {
26 6
            $schemaValidatorFactory->registerSchema($schemaLocation, $schemaLocation);
27
        }
28
29 6
        $schemaValidator = $schemaValidatorFactory->getValidator($schemaLocation);
30
31 6
        $checkRequest->setValidationResult($schemaValidator->validate($checkRequest->getContent()));
32 6
    }
33
34
    /**
35
     * @return SchemaValidatorFactoryInterface
36
     */
37
    abstract protected function getSchemaValidatorFactory(): SchemaValidatorFactoryInterface;
38
}
39