Completed
Pull Request — master (#39)
by Wachter
06:07
created

Configuration::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of php-task library.
5
 *
6
 * (c) php-task
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Task\TaskBundle\DependencyInjection;
13
14
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
15
use Symfony\Component\Config\Definition\ConfigurationInterface;
16
17
/**
18
 * Defines configuration for php-task library.
19
 */
20
class Configuration implements ConfigurationInterface
21
{
22
    /**
23
     * @var string[]
24
     */
25
    private $lockingStorageAliases = [];
26
27
    /**
28
     * @param \string[] $lockingStorageAliases
29
     */
30 25
    public function __construct(array $lockingStorageAliases)
31
    {
32 25
        $this->lockingStorageAliases = $lockingStorageAliases;
0 ignored issues
show
Documentation Bug introduced by
It seems like $lockingStorageAliases of type array<integer,object<string>> is incompatible with the declared type array<integer,string> of property $lockingStorageAliases.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
33 25
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 25
    public function getConfigTreeBuilder()
39
    {
40 25
        $treeBuilder = new TreeBuilder();
41
42 25
        $treeBuilder->root('task')
43 25
            ->children()
44 25
                ->enumNode('storage')->values(['array', 'doctrine'])->defaultValue('doctrine')->end()
45 25
                ->arrayNode('adapters')
46 25
                    ->addDefaultsIfNotSet()
47 25
                    ->children()
48 25
                        ->arrayNode('doctrine')
49 25
                            ->addDefaultsIfNotSet()
50 25
                            ->children()
51 25
                                ->booleanNode('clear')->defaultTrue()->end()
52 25
                            ->end()
53 25
                        ->end()
54 25
                    ->end()
55 25
                ->end()
56 25
                ->arrayNode('run')
57 25
                    ->addDefaultsIfNotSet()
58 25
                    ->children()
59 25
                        ->enumNode('mode')->values(['off', 'listener'])->defaultValue('off')->end()
60 25
                    ->end()
61 25
                ->end()
62 25
                ->arrayNode('locking')
63 25
                    ->canBeEnabled()
64 25
                    ->addDefaultsIfNotSet()
65 25
                    ->children()
66 25
                        ->enumNode('storage')
67 25
                            ->values(array_keys($this->lockingStorageAliases))
68 25
                            ->defaultValue('file')
69 25
                        ->end()
70 25
                        ->integerNode('ttl')->defaultValue(600)->end()
71 25
                        ->arrayNode('storages')
72 25
                            ->addDefaultsIfNotSet()
73 25
                            ->children()
74 25
                                ->arrayNode('file')
75 25
                                    ->addDefaultsIfNotSet()
76 25
                                    ->children()
77 25
                                        ->scalarNode('directory')->defaultValue('%kernel.cache_dir%/tasks')->end()
78 25
                                    ->end()
79 25
                                ->end()
80 25
                            ->end()
81 25
                        ->end()
82 25
                    ->end()
83 25
                ->end()
84 25
            ->end();
85
86 25
        return $treeBuilder;
87
    }
88
89
    /**
90
     * Returns id for given storage-alias.
91
     *
92
     * @param string $alias
93
     *
94
     * @return string
95
     */
96 25
    public function getLockingStorageId($alias)
97
    {
98 25
        return $this->lockingStorageAliases[$alias];
99
    }
100
}
101