TranslationAdapterTransifexExtension   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 31
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B load() 0 25 3
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\Transifex\Bridge\Symfony\DependencyInjection;
13
14
use Symfony\Component\DependencyInjection\ContainerBuilder;
15
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
16
use Translation\PlatformAdapter\Transifex\Transifex;
17
use BabDev\Transifex\Transifex as TransifexClient;
18
19
/**
20
 * @author Tobias Nyholm <[email protected]>
21
 */
22
class TranslationAdapterTransifexExtension extends Extension
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function load(array $configs, ContainerBuilder $container)
28
    {
29
        $configuration = new Configuration($container);
30
        $config = $this->processConfiguration($configuration, $configs);
31
32
        $domainToProjectMap = [];
33
        foreach ($config['projects'] as $project => $data) {
34
            foreach ($data['domains'] as $d) {
35
                $domainToProjectMap[$d] = $project;
36
            }
37
        }
38
39
        $apiDef = $container->register('php_translation.adapter.transifex.raw');
40
        $apiDef->setClass(TransifexClient::class);
41
        $apiDef->addArgument([
42
            'api.username' => $config['username'],
43
            'api.password' => $config['password'],
44
        ]);
45
46
        $adapterDef = $container->register('php_translation.adapter.transifex');
47
        $adapterDef
48
            ->setClass(Transifex::class)
49
            ->addArgument($apiDef)
50
            ->addArgument($domainToProjectMap);
51
    }
52
}
53