JsonApiErrorResponseExtension::load()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 17
cts 17
cp 1
rs 9.552
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 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 3
    public function load(array $configs, ContainerBuilder $container)
17
    {
18 3
        $config = $this->processConfiguration(new Configuration(), $configs);
19 3
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config/'));
20 3
        $loader->load('config.xml');
21
22 3
        $errorObjects = [];
23 3
        $exceptionsConfiguration = $config['exceptions']['response'];
24
25 3
        foreach ($exceptionsConfiguration as $exception => $config) {
26 1
            $errorObjects[$exception] = new Error(
27 1
                $config[Configuration::EXCEPTION_ATTRIBUTE_CODE],
28 1
                $config[Configuration::EXCEPTION_ATTRIBUTE_ID],
29 1
                $config[Configuration::EXCEPTION_ATTRIBUTE_ABOUT],
30 1
                $config[Configuration::EXCEPTION_ATTRIBUTE_STATUS],
31 1
                $config[Configuration::EXCEPTION_ATTRIBUTE_TITLE],
32 1
                $config[Configuration::EXCEPTION_ATTRIBUTE_DETAIL]
33
            );
34
        }
35
36 3
        $container->getDefinition(PreconfiguredExceptionsDescriber::class)
37 3
            ->replaceArgument(0, $exceptionsConfiguration);
38 3
    }
39
}
40