Passed
Branch master (7599c9)
by Ruslan
03:01 queued 12s
created

JsonApiErrorResponseExtension   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 16
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A load() 0 22 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Faecie\Bundle\JsonApiErrorResponseBundle\DependencyInjection;
6
7
use Faecie\Bundle\JsonApiErrorResponseBundle\ExceptionDescriber\PreconfiguredExceptionsDescriber;
8
use Faecie\Bundle\JsonApiErrorResponseBundle\JsonApi\Error;
9
use Symfony\Component\Config\FileLocator;
10
use Symfony\Component\DependencyInjection\ContainerBuilder;
11
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
12
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
13
14
class JsonApiErrorResponseExtension extends Extension
15
{
16
    public function load(array $configs, ContainerBuilder $container)
17
    {
18
        $config = $this->processConfiguration(new Configuration(), $configs);
19
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config/'));
20
        $loader->load('config.xml');
21
22
        $errorObjects = [];
23
        $exceptionsConfiguration = $config['exceptions']['response'];
24
25
        foreach ($exceptionsConfiguration as $exception => $config) {
26
            $errorObjects[$exception] = new Error(
27
                $config[Configuration::EXCEPTION_ATTRIBUTE_CODE],
28
                $config[Configuration::EXCEPTION_ATTRIBUTE_ID],
29
                $config[Configuration::EXCEPTION_ATTRIBUTE_ABOUT],
30
                $config[Configuration::EXCEPTION_ATTRIBUTE_STATUS],
31
                $config[Configuration::EXCEPTION_ATTRIBUTE_TITLE],
32
                $config[Configuration::EXCEPTION_ATTRIBUTE_DETAIL]
33
            );
34
        }
35
36
        $container->getDefinition(PreconfiguredExceptionsDescriber::class)
37
            ->replaceArgument(0, $exceptionsConfiguration);
38
    }
39
}
40