Completed
Pull Request — master (#4)
by Pavel
10:02
created

Configuration   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 90.74%

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 4
dl 0
loc 59
ccs 49
cts 54
cp 0.9074
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getConfigTreeBuilder() 0 55 1
1
<?php
2
3
namespace Bankiru\Api\DependencyInjection;
4
5
use Doctrine\Common\Cache\Cache;
6
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
7
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
8
use Symfony\Component\Config\Definition\ConfigurationInterface;
9
10
class Configuration implements ConfigurationInterface
11
{
12
    /** {@inheritdoc} */
13 6
    public function getConfigTreeBuilder()
14
    {
15 6
        $builder = new TreeBuilder();
16 6
        $root    = $builder->root('api_client');
17
18 6
        $logger = $root->children()->arrayNode('logger');
19 6
        $logger->addDefaultsIfNotSet();
20 6
        $logger->children()->scalarNode('id')->defaultValue('logger');
21
22 6
        $root->children()->booleanNode('profiling')->defaultValue('%kernel.debug%');
23
24 6
        $metadataCache = $root->children()->arrayNode('metadata_cache');
25 6
        $metadataCache->canBeEnabled();
26 6
        $metadataCache->children()->scalarNode('service')->info(
27
            Cache::class . ' Implementation service id. Required if enabled'
28 6
        )->defaultNull();
29 6
        $metadataCache->beforeNormalization()->ifString()->then(
30 1
            function ($v) {
31
                return ['service' => $v, 'enabled' => true];
32 1
            }
33 7
        );
34
35 6
        $cache = $root->children()->arrayNode('entity_cache');
36 7
        $cache->canBeEnabled();
37 7
        $cache->children()->scalarNode('service')->info('PSR-6 Cache service. Required if enabled');
38 7
        $cache->children()->scalarNode('logger')->defaultNull()->info('PSR-3 Log service for cache');
39 7
        $cache->beforeNormalization()->ifString()->then(
40 1
            function ($v) {
41 2
                return ['service' => $v, 'enabled' => true];
42 1
            }
43 7
        );
44 7
        $configuration = $cache->children()->arrayNode('configuration');
45 7
        $configuration->useAttributeAsKey('class');
46 1
        /** @var ArrayNodeDefinition $confProto */
47 7
        $confProto = $configuration->prototype('array');
48 7
        $confProto->children()->scalarNode('ttl')->isRequired();
49 7
        $confProto->beforeNormalization()
50 7
                  ->ifTrue(
51 1
                      function ($v) {
52 2
                          return is_int($v);
53 1
                      }
54 7
                  )
55 7
                  ->then(
56 2
                      function ($v) {
57 2
                          return ['ttl' => $v];
58 1
                      }
59 7
                  );
60 7
        $confProto->children()->variableNode('extra')
61 7
                  ->info('Extra data for entity cache configuration')
62 7
                  ->defaultValue([]);
63 7
        $confProto->ignoreExtraKeys(false);
64 7
        $confProto->canBeEnabled();
65 1
66 7
        return $builder;
67 1
    }
68
}
69