Definition::getConfigTreeBuilder()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 65
Code Lines 56

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 65
rs 9.3571
c 0
b 0
f 0
cc 3
eloc 56
nc 4
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
declare(strict_types=1);
4
5
/*
6
 * This file is part of the dotfiles project.
7
 *
8
 *     (c) Anthonius Munthi <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Dotfiles\Core\Config;
15
16
use Dotfiles\Core\Util\Toolkit;
17
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
18
19
class Definition implements DefinitionInterface
20
{
21
    public function getConfigTreeBuilder()
22
    {
23
        $builder = new TreeBuilder();
24
        $baseDir = Toolkit::getBaseDir();
25
        $tempDir = sys_get_temp_dir().'/dotfiles/temp';
26
27
        $backupDir = getenv('DOTFILES_BACKUP_DIR');
28
        $varDir = $backupDir.'/var';
29
        if (false === $backupDir) {
30
            $varDir = sys_get_temp_dir().'/dotfiles/var';
31
            $backupDir = sys_get_temp_dir().'/dotfiles/backup';
32
        }
33
        $homeDir = getenv('HOME');
34
35
        if ('dev' === getenv('DOTFILES_ENV')) {
36
            $homeDir = sys_get_temp_dir().'/dotfiles/home';
37
            $varDir = sys_get_temp_dir().'/dotfiles/var';
38
        }
39
40
        $root = $builder->root('dotfiles');
41
        $root
42
            ->children()
43
                ->scalarNode('backup_dir')
44
                    ->defaultValue($backupDir)
45
                ->end()
46
                ->scalarNode('env')
47
                    ->defaultValue(getenv('DOTFILES_ENV'))
48
                ->end()
49
                ->booleanNode('dry_run')
50
                    ->defaultTrue()
51
                ->end()
52
                ->scalarNode('machine_name')
53
                    ->defaultValue(getenv('DOTFILES_MACHINE_NAME'))
54
                ->end()
55
                ->scalarNode('home_dir')
56
                    ->defaultValue($homeDir)
57
                ->end()
58
                ->booleanNode('debug')
59
                    ->defaultFalse()
60
                ->end()
61
                ->scalarNode('base_dir')
62
                    ->defaultValue($baseDir)
63
                ->end()
64
                ->scalarNode('install_dir')
65
                    ->defaultValue('%dotfiles.home_dir%/.dotfiles')
66
                ->end()
67
                ->scalarNode('log_dir')
68
                    ->defaultValue($varDir.'/log')
69
                ->end()
70
                ->scalarNode('cache_dir')
71
                    ->defaultValue($varDir.'/cache')
72
                ->end()
73
                ->scalarNode('temp_dir')
74
                    ->defaultValue($tempDir)
75
                ->end()
76
                ->scalarNode('bin_dir')
77
                    ->defaultValue('%dotfiles.install_dir%/bin')
78
                ->end()
79
                ->scalarNode('vendor_dir')
80
                    ->defaultValue('%dotfiles.install_dir%/vendor')
81
                ->end()
82
            ->end()
83
        ;
84
85
        return $builder;
86
    }
87
}
88