GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

IvoryGoogleMapExtension   A
last analyzed

Complexity

Total Complexity 21

Size/Duplication

Total Lines 151
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 21
lcom 1
cbo 7
dl 0
loc 151
ccs 88
cts 88
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A loadInternal() 0 23 2
A loadMapConfig() 0 18 3
B loadStaticMapConfig() 0 18 6
A loadServicesConfig() 0 20 3
C loadServiceConfig() 0 42 7
1
<?php
2
3
/*
4
 * This file is part of the Ivory Google Map bundle package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ivory\GoogleMapBundle\DependencyInjection;
13
14
use Ivory\GoogleMap\Service\BusinessAccount;
15
use Symfony\Component\Config\FileLocator;
16
use Symfony\Component\Config\Loader\LoaderInterface;
17
use Symfony\Component\DependencyInjection\ContainerBuilder;
18
use Symfony\Component\DependencyInjection\Definition;
19
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
20
use Symfony\Component\DependencyInjection\Reference;
21
use Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension;
22
23
/**
24
 * @author GeLo <[email protected]>
25
 */
26
class IvoryGoogleMapExtension extends ConfigurableExtension
27
{
28
    /**
29
     * {@inheritdoc}
30
     */
31 522
    protected function loadInternal(array $config, ContainerBuilder $container)
32
    {
33 522
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
34
35
        $resources = [
36 522
            'form',
37 406
            'helper/collector',
38 406
            'helper/helper',
39 406
            'helper/renderer',
40 406
            'helper/subscriber',
41 406
            'helper/utility',
42 406
            'templating',
43 406
            'twig',
44 406
        ];
45
46 522
        foreach ($resources as $resource) {
47 522
            $loader->load($resource.'.xml');
48 406
        }
49
50 522
        $this->loadMapConfig($config['map'], $container);
51 522
        $this->loadStaticMapConfig($config['static_map'], $container);
52 522
        $this->loadServicesConfig($config, $container, $loader);
53 522
    }
54
55
    /**
56
     * @param mixed[]          $config
57
     * @param ContainerBuilder $container
58
     */
59 522
    private function loadMapConfig(array $config, ContainerBuilder $container)
60
    {
61
        $container
62 522
            ->getDefinition('ivory.google_map.helper.renderer.loader')
63 522
            ->addArgument($config['language']);
64
65 522
        if ($config['debug']) {
66
            $container
67 522
                ->getDefinition('ivory.google_map.helper.formatter')
68 522
                ->addArgument($config['debug']);
69 406
        }
70
71 522
        if (isset($config['api_key'])) {
72
            $container
73 9
                ->getDefinition('ivory.google_map.helper.renderer.loader')
74 9
                ->addArgument($config['api_key']);
75 7
        }
76 522
    }
77
78
    /**
79
     * @param mixed[]          $config
80
     * @param ContainerBuilder $container
81
     */
82 522
    private function loadStaticMapConfig(array $config, ContainerBuilder $container)
83
    {
84 522
        if (isset($config['api_key'])) {
85
            $container
86 18
                ->getDefinition('ivory.google_map.helper.subscriber.static.key')
87 18
                ->addArgument($config['api_key']);
88 14
        }
89
90 522
        if (isset($config['business_account'])) {
91 27
            $businessAccount = $config['business_account'];
92
93
            $container
94 27
                ->getDefinition('ivory.google_map.helper.map.static')
95 27
                ->addArgument(isset($businessAccount['secret']) ? $businessAccount['secret'] : null)
96 27
                ->addArgument(isset($businessAccount['client_id']) ? $businessAccount['client_id'] : null)
97 27
                ->addArgument(isset($businessAccount['channel']) ? $businessAccount['channel'] : null);
98 21
        }
99 522
    }
100
101
    /**
102
     * @param mixed[]          $config
103
     * @param ContainerBuilder $container
104
     * @param LoaderInterface  $loader
105
     */
106 522
    private function loadServicesConfig(array $config, ContainerBuilder $container, LoaderInterface $loader)
107
    {
108
        $services = [
109 522
            'direction'          => true,
110 406
            'distance_matrix'    => true,
111 406
            'elevation'          => true,
112 406
            'geocoder'           => true,
113 406
            'place_autocomplete' => true,
114 406
            'place_detail'       => true,
115 406
            'place_photo'        => false,
116 406
            'place_search'       => true,
117 406
            'time_zone'          => true,
118 406
        ];
119
120 522
        foreach ($services as $service => $http) {
121 522
            if (isset($config[$service])) {
122 424
                $this->loadServiceConfig($service, $config[$service], $container, $loader, $http);
123 308
            }
124 406
        }
125 522
    }
126
127
    /**
128
     * @param string           $service
129
     * @param mixed[]          $config
130
     * @param ContainerBuilder $container
131
     * @param LoaderInterface  $loader
132
     * @param bool             $http
133
     */
134 396
    private function loadServiceConfig(
135
        $service,
136
        array $config,
137
        ContainerBuilder $container,
138
        LoaderInterface $loader,
139
        $http = true
140
    ) {
141 396
        $loader->load('service/'.$service.'.xml');
142 396
        $definition = $container->getDefinition($serviceName = 'ivory.google_map.'.$service);
143
144 396
        if ($http) {
145 360
            $loader->load('service/serializer.xml');
146
147
            $definition
148 360
                ->addArgument(new Reference($config['client']))
149 360
                ->addArgument(new Reference($config['message_factory']))
150 360
                ->addArgument(new Reference('ivory.serializer'));
151 280
        }
152
153 396
        if ($http && isset($config['format'])) {
154 72
            $definition->addMethodCall('setFormat', [$config['format']]);
155 56
        }
156
157 396
        if (isset($config['api_key'])) {
158 81
            $definition->addMethodCall('setKey', [$config['api_key']]);
159 63
        }
160
161 396
        if (isset($config['business_account'])) {
162 162
            $businessAccountConfig = $config['business_account'];
163
164 162
            $container->setDefinition(
165 162
                $businessAccountName = $serviceName.'.business_account',
166 162
                new Definition(BusinessAccount::class, [
167 162
                    $businessAccountConfig['client_id'],
168 162
                    $businessAccountConfig['secret'],
169 162
                    isset($businessAccountConfig['channel']) ? $businessAccountConfig['channel'] : null,
170 126
                ])
171 126
            );
172
173 162
            $definition->addMethodCall('setBusinessAccount', [new Reference($businessAccountName)]);
174 126
        }
175 396
    }
176
}
177