Completed
Pull Request — master (#39)
by Wachter
04:59
created

Configuration::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 4
cts 4
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 29
    private $lockingStorageAliases = [];
26
27 29
    /**
28
     * @param \string[] $lockingStorageAliases
29 29
     */
30 29
    public function __construct(array $lockingStorageAliases)
31 29
    {
32 29
        $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 29
    }
34 29
35 29
    /**
36 29
     * {@inheritdoc}
37 29
     */
38 29
    public function getConfigTreeBuilder()
39 29
    {
40 29
        $treeBuilder = new TreeBuilder();
41 29
42 29
        $treeBuilder->root('task')
43 29
            ->children()
44 29
                ->enumNode('storage')->values(['array', 'doctrine'])->defaultValue('doctrine')->end()
45 29
                ->arrayNode('adapters')
46 29
                    ->addDefaultsIfNotSet()
47 29
                    ->children()
48 29
                        ->arrayNode('doctrine')
49 29
                            ->addDefaultsIfNotSet()
50 29
                            ->children()
51 29
                                ->booleanNode('clear')->defaultTrue()->end()
52 29
                            ->end()
53 29
                        ->end()
54 29
                    ->end()
55 29
                ->end()
56 29
                ->arrayNode('run')
57 29
                    ->addDefaultsIfNotSet()
58 29
                    ->children()
59 29
                        ->enumNode('mode')->values(['off', 'listener'])->defaultValue('off')->end()
60 29
                    ->end()
61 29
                ->end()
62 29
                ->arrayNode('locking')
63
                    ->canBeEnabled()
64 29
                    ->addDefaultsIfNotSet()
65
                    ->children()
66
                        ->enumNode('storage')
67
                            ->values(array_keys($this->lockingStorageAliases))
68
                            ->defaultValue('file')
69
                        ->end()
70
                        ->integerNode('ttl')->defaultValue(600)->end()
71
                        ->arrayNode('storages')
72
                            ->addDefaultsIfNotSet()
73
                            ->children()
74
                                ->arrayNode('file')
75
                                    ->addDefaultsIfNotSet()
76
                                    ->children()
77
                                        ->scalarNode('directory')->defaultValue('%kernel.cache_dir%/tasks')->end()
78
                                    ->end()
79
                                ->end()
80
                            ->end()
81
                        ->end()
82
                    ->end()
83
                ->end()
84
                ->arrayNode('system_tasks')
85
                    ->prototype('array')
86
                        ->children()
87
                            ->booleanNode('enabled')->defaultTrue()->end()
88
                            ->scalarNode('handler_class')->end()
89
                            ->variableNode('workload')->defaultNull()->end()
90
                            ->scalarNode('cron_expression')->end()
91
                        ->end()
92
                    ->end()
93
                ->end()
94
            ->end();
95
96
        return $treeBuilder;
97
    }
98
99
    /**
100
     * Returns id for given storage-alias.
101
     *
102
     * @param string $alias
103
     *
104
     * @return string
105
     */
106
    public function getLockingStorageId($alias)
107
    {
108
        return $this->lockingStorageAliases[$alias];
109
    }
110
}
111