Completed
Push — master ( 41d2c2...40d067 )
by Ryan
07:31
created

LoadModuleSeeders   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 4
c 1
b 1
f 0
lcom 1
cbo 2
dl 51
loc 51
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
B handle() 25 25 3

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\Streams\Platform\Installer\Console\Command;
2
3
use Anomaly\Streams\Platform\Addon\Module\Module;
4
use Anomaly\Streams\Platform\Addon\Module\ModuleCollection;
5
use Anomaly\Streams\Platform\Installer\Installer;
6
use Anomaly\Streams\Platform\Installer\InstallerCollection;
7
use App\Console\Kernel;
8
use Illuminate\Contracts\Bus\SelfHandling;
9
10
/**
11
 * Class LoadModuleSeeders
12
 *
13
 * @link          http://anomaly.is/streams-platform
14
 * @author        AnomalyLabs, Inc. <[email protected]>
15
 * @author        Ryan Thompson <[email protected]>
16
 * @package       Anomaly\Streams\Platform\Installer\Console\Command
17
 */
18 View Code Duplication
class LoadModuleSeeders implements SelfHandling
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
19
{
20
21
    /**
22
     * The installer collection.
23
     *
24
     * @var InstallerCollection
25
     */
26
    protected $installers;
27
28
    /**
29
     * Create a new LoadModuleSeeders instance.
30
     *
31
     * @param InstallerCollection $installers
32
     */
33
    public function __construct(InstallerCollection $installers)
34
    {
35
        $this->installers = $installers;
36
    }
37
38
    /**
39
     * Handle the command.
40
     *
41
     * @param ModuleCollection $modules
42
     */
43
    public function handle(ModuleCollection $modules)
44
    {
45
        /* @var Module $module */
46
        foreach ($modules as $module) {
47
48
            if ($module->getNamespace() == 'anomaly.module.installer') {
49
                continue;
50
            }
51
52
            $this->installers->add(
53
                new Installer(
54
                    trans('streams::installer.seeding', ['seeding' => trans($module->getName())]),
55
                    function (Kernel $console) use ($module) {
56
                        $console->call(
57
                            'db:seed',
58
                            [
59
                                '--addon' => $module->getNamespace(),
60
                                '--force' => true
61
                            ]
62
                        );
63
                    }
64
                )
65
            );
66
        }
67
    }
68
}
69