Completed
Push — master ( 381036...d6bde4 )
by Alexander
19:09
created

Configuration::getLockingStorageId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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\ArrayNodeDefinition;
15
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
16
use Symfony\Component\Config\Definition\ConfigurationInterface;
17
18
/**
19
 * Defines configuration for php-task library.
20
 */
21
class Configuration implements ConfigurationInterface
22
{
23
    /**
24
     * @var string[]
25
     */
26
    private $lockingStorageAliases = [];
27
28
    /**
29
     * @param \string[] $lockingStorageAliases
30
     */
31 2
    public function __construct(array $lockingStorageAliases)
32
    {
33 2
        $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...
34 2
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 2
    public function getConfigTreeBuilder()
40
    {
41 2
        $treeBuilder = new TreeBuilder('task');
42
43 2
        if (method_exists($treeBuilder, 'getRootNode')) {
44 2
            $rootNode = $treeBuilder->getRootNode();
45
        } else {
46
            // BC layer for symfony/config 4.1 and older
47
            $rootNode = $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...
48
        }
49
50
        $rootNode
51 2
            ->children()
52 2
                ->enumNode('storage')->values(['array', 'doctrine'])->defaultValue('doctrine')->end()
53 2
                ->arrayNode('adapters')
54 2
                    ->addDefaultsIfNotSet()
55 2
                    ->children()
56 2
                        ->arrayNode('doctrine')
57 2
                            ->addDefaultsIfNotSet()
58 2
                            ->children()
59 2
                                ->booleanNode('clear')->defaultTrue()->end()
60 2
                            ->end()
61 2
                        ->end()
62 2
                    ->end()
63 2
                ->end()
64 2
                ->arrayNode('run')
65 2
                    ->addDefaultsIfNotSet()
66 2
                    ->children()
67 2
                        ->enumNode('mode')->values(['off', 'listener'])->defaultValue('off')->end()
68 2
                    ->end()
69 2
                ->end()
70 2
                ->arrayNode('locking')
71 2
                    ->canBeEnabled()
72 2
                    ->addDefaultsIfNotSet()
73 2
                    ->children()
74 2
                        ->enumNode('storage')
75 2
                            ->values(array_keys($this->lockingStorageAliases))
76 2
                            ->defaultValue('file')
77 2
                        ->end()
78 2
                        ->integerNode('ttl')->defaultValue(600)->end()
79 2
                        ->arrayNode('storages')
80 2
                            ->addDefaultsIfNotSet()
81 2
                            ->children()
82 2
                                ->arrayNode('file')
83 2
                                    ->addDefaultsIfNotSet()
84 2
                                    ->children()
85 2
                                        ->scalarNode('directory')->defaultValue('%kernel.cache_dir%/tasks')->end()
86 2
                                    ->end()
87 2
                                ->end()
88 2
                            ->end()
89 2
                        ->end()
90 2
                    ->end()
91 2
                ->end()
92 2
                ->arrayNode('executor')
93 2
                    ->addDefaultsIfNotSet()
94 2
                    ->children()
95 2
                        ->enumNode('type')->values(['inside', 'separate'])->defaultValue('inside')->end()
96 2
                        ->arrayNode('separate')
97 2
                            ->addDefaultsIfNotSet()
98 2
                            ->children()
99 2
                                ->scalarNode('console_path')->defaultValue('%kernel.root_dir%/../bin/console')->end()
100 2
                                ->floatNode('process_timeout')->defaultNull()->end()
101 2
                            ->end()
102 2
                        ->end()
103 2
                    ->end()
104 2
                ->end()
105 2
                ->arrayNode('system_tasks')
106 2
                    ->prototype('array')
107 2
                        ->children()
108 2
                            ->booleanNode('enabled')->defaultTrue()->end()
109 2
                            ->scalarNode('handler_class')->end()
110 2
                            ->variableNode('workload')->defaultNull()->end()
111 2
                            ->scalarNode('cron_expression')->end()
112 2
                        ->end()
113 2
                    ->end()
114 2
                ->end()
115 2
            ->end();
116
117 2
        return $treeBuilder;
118
    }
119
120
    /**
121
     * Returns id for given storage-alias.
122
     *
123
     * @param string $alias
124
     *
125
     * @return string
126
     */
127 2
    public function getLockingStorageId($alias)
128
    {
129 2
        return $this->lockingStorageAliases[$alias];
130
    }
131
}
132