Completed
Push — master ( b54433...61ac55 )
by Tobias
03:06
created

TranslationAdapterLocoExtension::load()   C

Complexity

Conditions 7
Paths 3

Size

Total Lines 36
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 7.392

Importance

Changes 0
Metric Value
dl 0
loc 36
ccs 16
cts 20
cp 0.8
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 26
nc 3
nop 2
crap 7.392
1
<?php
2
3
/*
4
 * This file is part of the PHP Translation package.
5
 *
6
 * (c) PHP Translation team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Translation\PlatformAdapter\Loco\Bridge\Symfony\DependencyInjection;
13
14
use FAPI\Localise\HttpClientConfigurator;
15
use FAPI\Localise\LocoClient;
16
use FAPI\Localise\RequestBuilder;
17
use Symfony\Component\DependencyInjection\ContainerBuilder;
18
use Symfony\Component\DependencyInjection\Definition;
19
use Symfony\Component\DependencyInjection\Reference;
20
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
21
use Translation\PlatformAdapter\Loco\Loco;
22
23
/**
24
 * @author Tobias Nyholm <[email protected]>
25
 */
26
class TranslationAdapterLocoExtension extends Extension
27
{
28
    /**
29
     * {@inheritdoc}
30
     */
31 1
    public function load(array $configs, ContainerBuilder $container)
32
    {
33 1
        $configuration = new Configuration($container);
0 ignored issues
show
Unused Code introduced by
The call to Configuration::__construct() has too many arguments starting with $container.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
34 1
        $config = $this->processConfiguration($configuration, $configs);
35
36 1
        $domainToProjectMap = [];
37 1
        foreach ($config['projects'] as $domain => $data) {
38
            if (empty($data['domains'])) {
39
                $domainToProjectMap[$domain] = $data['api_key'];
40
            } else {
41
                foreach ($data['domains'] as $d) {
42
                    $domainToProjectMap[$d] = $data['api_key'];
43
                }
44
            }
45
        }
46
47
        $requestBuilder = (new Definition(RequestBuilder::class))
48 1
            ->addArgument(empty($config['httplug_message_factory']) ? null : new Reference($config['httplug_message_factory']));
49
50
        $clientConfigurator = (new Definition(HttpClientConfigurator::class))
51 1
            ->addArgument(empty($config['httplug_client']) ? null : new Reference($config['httplug_client']))
52 1
            ->addArgument(empty($config['httplug_uri_factory']) ? null : new Reference($config['httplug_uri_factory']));
53
54 1
        $apiDef = $container->register('php_translation.adapter.loco.raw');
55
        $apiDef->setClass(LocoClient::class)
56
            ->setFactory([LocoClient::class, 'configure'])
57 1
            ->addArgument($clientConfigurator)
58 1
            ->addArgument(null)
59 1
            ->addArgument($requestBuilder);
60
61 1
        $adapterDef = $container->register('php_translation.adapter.loco');
62
        $adapterDef
63
            ->setClass(Loco::class)
64 1
            ->addArgument($apiDef)
65 1
            ->addArgument($domainToProjectMap);
66 1
    }
67
}
68