RedirectionIOExtension   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 32
c 0
b 0
f 0
dl 0
loc 52
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A load() 0 47 5
1
<?php
2
3
namespace RedirectionIO\Client\ProxySymfony\DependencyInjection;
4
5
use RedirectionIO\Client\ProxySymfony\CircuitBreaker\CircuitBreakerInterface;
6
use RedirectionIO\Client\ProxySymfony\CircuitBreaker\HostBreaker;
7
use RedirectionIO\Client\ProxySymfony\CircuitBreaker\PathInfoPrefixBreaker;
8
use RedirectionIO\Client\ProxySymfony\EventListener\RequestResponseListener;
9
use RedirectionIO\Client\Sdk\Client;
10
use Symfony\Component\Config\FileLocator;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Config\FileLocator was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Symfony\Component\DependencyInjection\ContainerBuilder;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Depend...ection\ContainerBuilder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Depend...on\Loader\XmlFileLoader was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
14
15
/**
16
 * @internal
17
 */
18
final class RedirectionIOExtension extends Extension
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function load(array $configs, ContainerBuilder $container)
24
    {
25
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
26
        $loader->load('services.xml');
27
28
        $configuration = new Configuration();
29
        $config = $this->processConfiguration($configuration, $configs);
30
31
        foreach ($config['connections'] as $name => $connection) {
32
            $connections[$name] = $container->resolveEnvPlaceholders($connection);
33
        }
34
35
        $container
36
            ->getDefinition(Client::class)
37
            ->replaceArgument(0, $config['project_key'])
38
            ->replaceArgument(1, $connections)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $connections seems to be defined by a foreach iteration on line 31. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
39
            ->replaceArgument(3, $config['debug'])
40
            ->replaceArgument(5, $config['persist'])
41
        ;
42
43
        $container
44
            ->getDefinition(RequestResponseListener::class)
45
            ->replaceArgument(1, $config['match_on_response'])
46
        ;
47
48
        if ($config['excluded_prefixes']) {
49
            $container
50
                ->getDefinition(PathInfoPrefixBreaker::class)
51
                ->replaceArgument(0, $config['excluded_prefixes'])
52
            ;
53
        } else {
54
            $container->removeDefinition(PathInfoPrefixBreaker::class);
55
        }
56
57
        if ($config['excluded_hosts']) {
58
            $container
59
                ->getDefinition(HostBreaker::class)
60
                ->replaceArgument(0, $config['excluded_hosts'])
61
            ;
62
        } else {
63
            $container->removeDefinition(HostBreaker::class);
64
        }
65
66
        if (method_exists($container, 'registerForAutoconfiguration')) {
67
            $container
68
                ->registerForAutoconfiguration(CircuitBreakerInterface::class)
69
                ->addTag('redirectionio.circuit_breaker')
70
            ;
71
        }
72
    }
73
}
74