Completed
Pull Request — master (#39)
by Wachter
24:21
created

Configuration::getLockingStorageId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
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 25
    private $lockingStorageAliases = [];
26
27 25
    /**
28
     * @param \string[] $lockingStorageAliases
29 25
     */
30 25
    public function __construct(array $lockingStorageAliases)
31 25
    {
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 25
35 25
    /**
36 25
     * {@inheritdoc}
37 25
     */
38 25
    public function getConfigTreeBuilder()
39 25
    {
40 25
        $treeBuilder = new TreeBuilder();
41 25
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
                        ->end()
54 25
                    ->end()
55
                ->end()
56
                ->arrayNode('run')
57
                    ->addDefaultsIfNotSet()
58
                    ->children()
59
                        ->enumNode('mode')->values(['off', 'listener'])->defaultValue('off')->end()
60
                    ->end()
61
                ->end()
62
                ->arrayNode('locking')
63
                    ->addDefaultsIfNotSet()
64
                    ->children()
65
                        ->enumNode('storage')
66
                            ->values(array_keys($this->lockingStorageAliases))
67
                            ->defaultValue('file')
68
                        ->end()
69
                        ->arrayNode('storages')
70
                            ->addDefaultsIfNotSet()
71
                            ->children()
72
                                ->arrayNode('file')
73
                                    ->addDefaultsIfNotSet()
74
                                    ->children()
75
                                        ->scalarNode('directory')->defaultValue(sys_get_temp_dir() . '/task')->end()
76
                                    ->end()
77
                                ->end()
78
                            ->end()
79
                        ->end()
80
                        ->enumNode('mode')->values(['off', 'listener'])->defaultValue('off')->end()
81
                    ->end()
82
                ->end()
83
            ->end();
84
85
        return $treeBuilder;
86
    }
87
88
    /**
89
     * Returns id for given storage-alias.
90
     *
91
     * @param string $alias
92
     *
93
     * @return string
94
     */
95
    public function getLockingStorageId($alias)
96
    {
97
        return $this->lockingStorageAliases[$alias];
98
    }
99
}
100