Completed
Push — symfony-4-upgrade-fix ( 61651d...1f1d06 )
by
unknown
06:14
created

Configuration::getConfigTreeBuilder()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 57

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 57
c 0
b 0
f 0
rs 8.9381
cc 2
nc 2
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace MyBuilder\Bundle\CronosBundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6
use Symfony\Component\Config\Definition\ConfigurationInterface;
7
8
class Configuration implements ConfigurationInterface
9
{
10
    public function getConfigTreeBuilder(): TreeBuilder
11
    {
12
        if (method_exists(TreeBuilder::class, 'getRootNode')) {
13
            $treeBuilder = new TreeBuilder('my_builder_cronos');
14
            $rootNode = $treeBuilder->getRootNode();
15
        } else {
16
            $treeBuilder = new TreeBuilder();
0 ignored issues
show
Bug introduced by
The call to TreeBuilder::__construct() misses a required argument $name.

This check looks for function calls that miss required arguments.

Loading history...
17
            $rootNode = $treeBuilder->root('my_builder_cronos');
0 ignored issues
show
Bug introduced by
The method root() does not seem to exist on object<Symfony\Component...on\Builder\TreeBuilder>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
18
        }
19
20
        $rootNode
21
            ->children()
22
                ->arrayNode('exporter')
23
                    ->addDefaultsIfNotSet()
24
                    ->children()
25
                        ->scalarNode('key')
26
                            ->isRequired()
27
                            ->cannotBeEmpty()
28
                            ->info('Unique key that wraps all the cron configured for the current application.')
29
                            ->example('my_symfony_app')
30
                        ->end()
31
                        ->scalarNode('mailto')
32
                            ->cannotBeEmpty()
33
                            ->info('Sets the default email address for all cron output to go to.')
34
                            ->example('[email protected]')
35
                        ->end()
36
                        ->scalarNode('path')
37
                            ->example('/usr/local/bin:/usr/bin:/bin')
38
                            ->info('Sets the path for all commands in the crontab.')
39
                        ->end()
40
                        ->scalarNode('executor')
41
                            ->cannotBeEmpty()
42
                            ->defaultValue('php')
43
                            ->example('php')
44
                            ->info('Allows you to specify a program that all commands should be passed to such as "/usr/local/bin/php".')
45
                        ->end()
46
                        ->scalarNode('console')
47
                            ->cannotBeEmpty()
48
                            ->defaultValue('%kernel.root_dir%/../bin/console')
49
                            ->example('%kernel.project_dir%/bin/console')
50
                            ->info('Allows you to specify the console that all commands should be passed to such as "bin/console".')
51
                        ->end()
52
                        ->scalarNode('shell')
53
                            ->cannotBeEmpty()
54
                            ->example('/bin/sh')
55
                            ->info('Allows you to specify which shell each program should be run with.')
56
                        ->end()
57
                        ->scalarNode('timezone')
58
                            ->example('Europe/Paris')
59
                            ->info('Allows you to add CRON_TZ which specifies the time zone specific for the cron table.')
60
                        ->end()
61
                    ->end()
62
                ->end()
63
            ->end();
64
65
        return $treeBuilder;
66
    }
67
}
68