ConfigureSystem::handle()   F
last analyzed

Complexity

Conditions 24
Paths 294

Size

Total Lines 89
Code Lines 43

Duplication

Lines 54
Ratio 60.67 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 54
loc 89
rs 3.5633
cc 24
eloc 43
nc 294
nop 4

How to fix   Long Method    Complexity   

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 namespace Anomaly\SettingsModule\Setting\Command;
2
3
use Anomaly\SettingsModule\Setting\Contract\SettingRepositoryInterface;
4
use Anomaly\Streams\Platform\Addon\Addon;
5
use Anomaly\Streams\Platform\Addon\AddonCollection;
6
use Anomaly\Streams\Platform\Support\Evaluator;
7
use Illuminate\Contracts\Config\Repository;
8
9
/**
10
 * Class ConfigureSystem
11
 *
12
 * @link          http://pyrocms.com/
13
 * @author        PyroCMS, Inc. <[email protected]>
14
 * @author        Ryan Thompson <[email protected]>
15
 */
16
class ConfigureSystem
17
{
18
19
    /**
20
     * Handle the command.
21
     *
22
     * @param SettingRepositoryInterface $settings
23
     * @param AddonCollection            $addons
24
     * @param Evaluator                  $evaluator
25
     * @param Repository                 $config
26
     */
27
    public function handle(
28
        SettingRepositoryInterface $settings,
29
        AddonCollection $addons,
30
        Evaluator $evaluator,
31
        Repository $config
32
    ) {
33
        /* @var Addon $addon */
34 View Code Duplication
        foreach ($addons->withConfig('settings') as $addon) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
            foreach ($config->get($addon->getNamespace('settings')) as $key => $setting) {
36
37
                if (isset($setting['env']) && env($setting['env']) !== null) {
38
                    continue;
39
                }
40
41
                if (!isset($setting['bind'])) {
42
                    continue;
43
                }
44
45
                $default = array_get($setting, 'config.default_value');
46
47
                if (!$settings->has($key = $addon->getNamespace($key)) && !$default) {
48
                    continue;
49
                }
50
51
                if ($presenter = $settings->presenter($key)) {
52
53
                    $config->set($setting['bind'], $presenter->__value());
54
55
                    continue;
56
                }
57
58
                $config->set($setting['bind'], $evaluator->evaluate($default));
59
            }
60
        }
61
62 View Code Duplication
        foreach ($addons->withConfig('settings/settings') as $addon) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
63
            foreach ($config->get($addon->getNamespace('settings/settings')) as $key => $setting) {
64
65
                if (isset($setting['env']) && env($setting['env']) !== null) {
66
                    continue;
67
                }
68
69
                if (!isset($setting['bind'])) {
70
                    continue;
71
                }
72
73
                $default = array_get($setting, 'config.default_value');
74
75
                if (!$settings->has($key = $addon->getNamespace($key)) && !$default) {
76
                    continue;
77
                }
78
79
                if ($presenter = $settings->presenter($key)) {
80
81
                    $config->set($setting['bind'], $presenter->__value());
82
83
                    continue;
84
                }
85
86
                $config->set($setting['bind'], $evaluator->evaluate($default));
87
            }
88
        }
89
90
        foreach ($config->get('streams::settings/settings', []) as $key => $setting) {
91
92
            if (isset($setting['env']) && env($setting['env']) !== null) {
93
                continue;
94
            }
95
96
            if (!isset($setting['bind'])) {
97
                continue;
98
            }
99
100
            $default = array_get($setting, 'config.default_value');
101
102
            if (!$settings->has($key = 'streams::' . $key) && !$default) {
103
                continue;
104
            }
105
106
            if ($presenter = $settings->presenter($key)) {
107
108
                $config->set($setting['bind'], $presenter->__value());
109
110
                continue;
111
            }
112
113
            $config->set($setting['bind'], $evaluator->evaluate($default));
114
        }
115
    }
116
}
117