Code Duplication    Length = 45-45 lines in 2 locations

src/EventListener/JsonCheckSchemaSubscriber.php 1 location

@@ 13-57 (lines=45) @@
10
use Symfony\Component\Config\Exception\FileLocatorFileNotFoundException;
11
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
12
13
class JsonCheckSchemaSubscriber implements EventSubscriberInterface
14
{
15
    /**
16
     * @var JsonSchemaValidatorFactory
17
     */
18
    protected $jsonSchemaValidatorFactory;
19
20
    /**
21
     * @param JsonSchemaValidatorFactory $jsonSchemaValidatorFactory
22
     */
23
    public function __construct(JsonSchemaValidatorFactory $jsonSchemaValidatorFactory)
24
    {
25
        $this->jsonSchemaValidatorFactory = $jsonSchemaValidatorFactory;
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public static function getSubscribedEvents(): array
32
    {
33
        return [
34
            Events::getCheckSchemaEventNameFor('json') => 'validateSchema',
35
        ];
36
    }
37
38
    /**
39
     * @param CheckRequest $checkRequest
40
     *
41
     * @throws \RuntimeException
42
     * @throws \InvalidArgumentException
43
     * @throws FileLocatorFileNotFoundException
44
     */
45
    public function validateSchema(CheckRequest $checkRequest): void
46
    {
47
        $schemaLocation = $checkRequest->getResponseSchemaLocation();
48
49
        if (!$this->jsonSchemaValidatorFactory->hasSchema($schemaLocation)) {
50
            $this->jsonSchemaValidatorFactory->registerSchema($schemaLocation, $schemaLocation);
51
        }
52
53
        $schemaValidator = $this->jsonSchemaValidatorFactory->getValidator($schemaLocation);
54
55
        $checkRequest->setValidationResult($schemaValidator->validate($checkRequest->getContent()));
56
    }
57
}
58

src/EventListener/XmlCheckSchemaSubscriber.php 1 location

@@ 13-57 (lines=45) @@
10
use Symfony\Component\Config\Exception\FileLocatorFileNotFoundException;
11
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
12
13
class XmlCheckSchemaSubscriber implements EventSubscriberInterface
14
{
15
    /**
16
     * @var XmlSchemaValidatorFactory
17
     */
18
    protected $xmlSchemaValidatorFactory;
19
20
    /**
21
     * @param XmlSchemaValidatorFactory $xmlSchemaValidatorFactory
22
     */
23
    public function __construct(XmlSchemaValidatorFactory $xmlSchemaValidatorFactory)
24
    {
25
        $this->xmlSchemaValidatorFactory = $xmlSchemaValidatorFactory;
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public static function getSubscribedEvents(): array
32
    {
33
        return [
34
            Events::getCheckSchemaEventNameFor('xml') => 'validateSchema',
35
        ];
36
    }
37
38
    /**
39
     * @param CheckRequest $checkRequest
40
     *
41
     * @throws \RuntimeException
42
     * @throws \InvalidArgumentException
43
     * @throws FileLocatorFileNotFoundException
44
     */
45
    public function validateSchema(CheckRequest $checkRequest): void
46
    {
47
        $schemaLocation = $checkRequest->getResponseSchemaLocation();
48
49
        if (!$this->xmlSchemaValidatorFactory->hasSchema($schemaLocation)) {
50
            $this->xmlSchemaValidatorFactory->registerSchema($schemaLocation, $schemaLocation);
51
        }
52
53
        $schemaValidator = $this->xmlSchemaValidatorFactory->getValidator($schemaLocation);
54
55
        $checkRequest->setValidationResult($schemaValidator->validate($checkRequest->getContent()));
56
    }
57
}
58