FormatValidatorPass::process()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 0
cts 10
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 3
nop 1
crap 12
1
<?php
2
3
namespace Nicofuma\SwaggerBundle\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Reference;
8
9
class FormatValidatorPass implements CompilerPassInterface
10
{
11
    /**
12
     * {@inheritdoc}
13
     */
14
    public function process(ContainerBuilder $container)
15
    {
16
        $constraintFactoryDefinition = $container->getDefinition('swagger.json_schema.constraints.factory');
17
        $formatConstraintDefinition = $container->getDefinition('swagger.json_schema.constraints.format');
18
19
        $services = $container->findTaggedServiceIds('swagger.format_validator');
20
        foreach ($services as $serviceId => $tags) {
21
            foreach ($tags as $attributes) {
22
                $formatConstraintDefinition->addMethodCall('addFormatValidator', [$attributes['format'], new Reference($serviceId)]);
23
                $constraintFactoryDefinition->addMethodCall('setFormatValidator', [$attributes['format'], new Reference($serviceId)]);
24
            }
25
        }
26
    }
27
}
28