Configuration::getProjectNode()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 28
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 23
c 2
b 0
f 0
nc 2
nop 0
dl 0
loc 28
ccs 16
cts 16
cp 1
crap 2
rs 9.552
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 Symfony\Component\Config\Definition\Builder\TreeBuilder;
15
use Symfony\Component\Config\Definition\ConfigurationInterface;
16
17
/**
18
 * @author Tobias Nyholm <[email protected]>
19
 */
20
class Configuration implements ConfigurationInterface
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25 1
    public function getConfigTreeBuilder()
26
    {
27 1
        $treeBuilder = new TreeBuilder('translation_adapter_loco');
28 1
        // Keep compatibility with symfony/config < 4.2
29
        if (!method_exists($treeBuilder, 'getRootNode')) {
30
            $root = $treeBuilder->root('translation_adapter_loco');
0 ignored issues
show
Bug introduced by
The method root() does not exist on Symfony\Component\Config...ion\Builder\TreeBuilder. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
            /** @scrutinizer ignore-call */ 
31
            $root = $treeBuilder->root('translation_adapter_loco');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
31 1
        } else {
32 1
            $root = $treeBuilder->getRootNode();
33 1
        }
34 1
35 1
        $root
36 1
            ->children()
37 1
                ->scalarNode('httplug_client')->defaultNull()->end()
38 1
                ->scalarNode('httplug_message_factory')->defaultNull()->end()
39 1
                ->scalarNode('httplug_uri_factory')->defaultNull()->end()
40 1
                ->scalarNode('index_parameter')
41 1
                    ->info('Index parameter sent to loco api to all your domains. Specify whether file indexes translations by asset ID or source texts')
42
                    ->example('id')
43 1
                    ->defaultNull()
44
                ->end()
45
                ->append($this->getProjectNode())
46
            ->end();
47
48
        return $treeBuilder;
49 1
    }
50
51 1
    /**
52 1
     * @return \Symfony\Component\Config\Definition\Builder\NodeDefinition
53
     */
54 1
    private function getProjectNode()
55 1
    {
56 1
        $treeBuilder = new TreeBuilder('projects');
57 1
        // Keep compatibility with symfony/config < 4.2
58 1
        if (!method_exists($treeBuilder, 'getRootNode')) {
59 1
            $node = $treeBuilder->root('projects');
60 1
        } else {
61 1
            $node = $treeBuilder->getRootNode();
62 1
        }
63 1
        $node
64 1
            ->useAttributeAsKey('name')
65 1
            ->prototype('array')
66 1
            ->children()
67 1
                ->scalarNode('api_key')->isRequired()->end()
68 1
                ->scalarNode('status')->defaultValue('translated')->end()
69
                ->scalarNode('index_parameter')
70 1
                    ->info('Index parameter sent to loco api for this particular domain (overrides global one). Specify whether file indexes translations by asset ID or source texts')
71
                    ->example('id')
72
                    ->defaultNull()
73
                ->end()
74
                ->arrayNode('domains')
75
                    ->requiresAtLeastOneElement()
76
                    ->prototype('scalar')->end()
77
                ->end()
78
            ->end()
79
        ->end();
80
81
        return $node;
82
    }
83
}
84