Completed
Pull Request — master (#47)
by Wachter
06:41 queued 17s
created

Configuration   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 104
ccs 0
cts 79
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B getConfigTreeBuilder() 0 73 1
A getLockingStorageId() 0 4 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
    public function __construct(array $lockingStorageAliases)
31
    {
32
        $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
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function getConfigTreeBuilder()
39
    {
40
        $treeBuilder = new TreeBuilder();
41
42
        $treeBuilder->root('task')
0 ignored issues
show
Deprecated Code introduced by
The method Symfony\Component\Config...der\TreeBuilder::root() has been deprecated with message: since Symfony 4.3, pass the root name to the constructor instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
43
            ->children()
44
                ->enumNode('storage')->values(['array', 'doctrine'])->defaultValue('doctrine')->end()
45
                ->arrayNode('adapters')
46
                    ->addDefaultsIfNotSet()
47
                    ->children()
48
                        ->arrayNode('doctrine')
49
                            ->addDefaultsIfNotSet()
50
                            ->children()
51
                                ->booleanNode('clear')->defaultTrue()->end()
52
                            ->end()
53
                        ->end()
54
                    ->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
                    ->canBeEnabled()
64
                    ->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('executor')
85
                    ->addDefaultsIfNotSet()
86
                    ->children()
87
                        ->enumNode('type')->values(['inside', 'separate'])->defaultValue('inside')->end()
88
                        ->arrayNode('separate')
89
                            ->addDefaultsIfNotSet()
90
                            ->children()
91
                                ->scalarNode('console_path')->defaultValue('%kernel.root_dir%/../bin/console')->end()
92
                                ->floatNode('process_timeout')->defaultNull()->end()
93
                            ->end()
94
                        ->end()
95
                    ->end()
96
                ->end()
97
                ->arrayNode('system_tasks')
98
                    ->prototype('array')
99
                        ->children()
100
                            ->booleanNode('enabled')->defaultTrue()->end()
101
                            ->scalarNode('handler_class')->end()
102
                            ->variableNode('workload')->defaultNull()->end()
103
                            ->scalarNode('cron_expression')->end()
104
                        ->end()
105
                    ->end()
106
                ->end()
107
            ->end();
108
109
        return $treeBuilder;
110
    }
111
112
    /**
113
     * Returns id for given storage-alias.
114
     *
115
     * @param string $alias
116
     *
117
     * @return string
118
     */
119
    public function getLockingStorageId($alias)
120
    {
121
        return $this->lockingStorageAliases[$alias];
122
    }
123
}
124