ConfigureSystem   A
last analyzed

Complexity

Total Complexity 24

Size/Duplication

Total Lines 101
Duplicated Lines 53.47 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 24
c 1
b 0
f 0
lcom 0
cbo 1
dl 54
loc 101
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
F handle() 54 89 24

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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