Completed
Push — master ( 7a0906...3ff6f8 )
by Ryan
02:30
created

ConfigureSystem::handle()   C

Complexity

Conditions 18
Paths 180

Size

Total Lines 61
Code Lines 30

Duplication

Lines 36
Ratio 59.02 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 36
loc 61
rs 5.6279
cc 18
eloc 30
nc 180
nop 3

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 Illuminate\Contracts\Bus\SelfHandling;
7
use Illuminate\Contracts\Config\Repository;
8
use Illuminate\Contracts\Foundation\Application;
9
10
/**
11
 * Class ConfigureSystem
12
 *
13
 * @link          http://pyrocms.com/
14
 * @author        PyroCMS, Inc. <[email protected]>
15
 * @author        Ryan Thompson <[email protected]>
16
 * @package       Anomaly\SettingsModule\Setting\Command
17
 */
18
class ConfigureSystem implements SelfHandling
19
{
20
21
    /**
22
     * Configuration to setting map.
23
     *
24
     * @var array
25
     */
26
    protected $settings = [
27
        'mail.driver'   => 'streams::mail_driver',
28
        'mail.host'     => 'streams::mail_host',
29
        'mail.port'     => 'streams::mail_port',
30
        'mail.username' => 'streams::mail_username',
31
        'mail.password' => 'streams::mail_password',
32
        'mail.pretend'  => 'streams::mail_debug'
33
    ];
34
35
    /**
36
     * Handle the command.
37
     *
38
     * @param SettingRepositoryInterface $settings
39
     * @param AddonCollection            $addons
40
     * @param Repository                 $config
41
     */
42
    public function handle(
43
        SettingRepositoryInterface $settings,
44
        AddonCollection $addons,
45
        Repository $config
46
    ) {
47
        /* @var Addon $addon */
48 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...
49
            foreach ($config->get($addon->getNamespace('settings')) as $key => $setting) {
50
51
                if (isset($setting['env']) && env($setting['env']) !== null) {
52
                    continue;
53
                }
54
55
                if (!isset($setting['replace'])) {
56
                    continue;
57
                }
58
59
                if (!$settings->has($key = $addon->getNamespace($key))) {
60
                    continue;
61
                }
62
63
                $config->set($setting['replace'], $settings->value($key));
64
            }
65
        }
66
67 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...
68
            foreach ($config->get($addon->getNamespace('settings/settings')) as $key => $setting) {
69
70
                if (isset($setting['env']) && env($setting['env']) !== null) {
71
                    continue;
72
                }
73
74
                if (!isset($setting['replace'])) {
75
                    continue;
76
                }
77
78
                if (!$settings->has($key = $addon->getNamespace($key))) {
79
                    continue;
80
                }
81
82
                $config->set($setting['replace'], $settings->value($key));
83
            }
84
        }
85
86
        foreach ($config->get('streams::settings/settings') as $key => $setting) {
87
88
            if (isset($setting['env']) && env($setting['env']) !== null) {
89
                continue;
90
            }
91
92
            if (!isset($setting['replace'])) {
93
                continue;
94
            }
95
96
            if (!$settings->has($key = 'streams::' . $key)) {
97
                continue;
98
            }
99
100
            $config->set($setting['replace'], $settings->value($key));
101
        }
102
    }
103
}
104