Completed
Pull Request — master (#34)
by Jo
03:25 queued 02:20
created

Configuration::getConfigTreeBuilder()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 59

Duplication

Lines 0
Ratio 0 %

Importance

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