Completed
Push — master ( 98a062...441031 )
by Ryan
10:10
created

Make   C

Complexity

Total Complexity 5

Size/Duplication

Total Lines 91
Duplicated Lines 7.69 %

Coupling/Cohesion

Components 1
Dependencies 19

Importance

Changes 0
Metric Value
dl 7
loc 91
rs 6.875
c 0
b 0
f 0
wmc 5
lcom 1
cbo 19

3 Methods

Rating   Name   Duplication   Size   Complexity  
B fire() 0 42 3
A getArguments() 0 7 1
A getOptions() 7 7 1

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\Stream\Console;
2
3
use Anomaly\Streams\Platform\Addon\Addon;
4
use Anomaly\Streams\Platform\Addon\AddonCollection;
5
use Anomaly\Streams\Platform\Stream\Console\Command\WriteEntityCollection;
6
use Anomaly\Streams\Platform\Stream\Console\Command\WriteEntityController;
7
use Anomaly\Streams\Platform\Stream\Console\Command\WriteEntityCriteria;
8
use Anomaly\Streams\Platform\Stream\Console\Command\WriteEntityFactory;
9
use Anomaly\Streams\Platform\Stream\Console\Command\WriteEntityFormBuilder;
10
use Anomaly\Streams\Platform\Stream\Console\Command\WriteEntityModel;
11
use Anomaly\Streams\Platform\Stream\Console\Command\WriteEntityModelInterface;
12
use Anomaly\Streams\Platform\Stream\Console\Command\WriteEntityObserver;
13
use Anomaly\Streams\Platform\Stream\Console\Command\WriteEntityPresenter;
14
use Anomaly\Streams\Platform\Stream\Console\Command\WriteEntityRepository;
15
use Anomaly\Streams\Platform\Stream\Console\Command\WriteEntityRepositoryInterface;
16
use Anomaly\Streams\Platform\Stream\Console\Command\WriteEntityRouter;
17
use Anomaly\Streams\Platform\Stream\Console\Command\WriteEntityRoutes;
18
use Anomaly\Streams\Platform\Stream\Console\Command\WriteEntitySeeder;
19
use Anomaly\Streams\Platform\Stream\Console\Command\WriteEntityTableBuilder;
20
use Anomaly\Streams\Platform\Stream\Console\Command\WriteEntityTestCases;
21
use Illuminate\Console\Command;
22
use Illuminate\Foundation\Bus\DispatchesJobs;
23
use Symfony\Component\Console\Input\InputArgument;
24
use Symfony\Component\Console\Input\InputOption;
25
26
/**
27
 * Class Make
28
 *
29
 * @link   http://pyrocms.com/
30
 * @author PyroCMS, Inc. <[email protected]>
31
 * @author Ryan Thompson <[email protected]>
32
 */
33
class Make extends Command
34
{
35
36
    use DispatchesJobs;
37
38
    /**
39
     * The console command name.
40
     *
41
     * @var string
42
     */
43
    protected $name = 'make:stream';
44
45
    /**
46
     * The console command description.
47
     *
48
     * @var string
49
     */
50
    protected $description = 'Make a streams entity namespace.';
51
52
    /**
53
     * Execute the console command.
54
     */
55
    public function fire(AddonCollection $addons)
56
    {
57
        $slug  = $this->argument('slug');
58
        $addon = $this->argument('addon');
59
60
        /* @var Addon $addon */
61
        if (!$addon = $addons->get($addon)) {
62
            throw new \Exception("The addon [{$this->argument('addon')}] could not be found.");
63
        }
64
65
        if (!$namespace = $this->option('namespace')) {
66
            $namespace = $addon->getSlug();
67
        }
68
69
        $this->dispatch(new WriteEntityModel($addon, $slug, $namespace));
70
        $this->dispatch(new WriteEntityRoutes($addon, $slug, $namespace));
71
        $this->dispatch(new WriteEntityRouter($addon, $slug, $namespace));
72
        $this->dispatch(new WriteEntitySeeder($addon, $slug, $namespace));
73
        $this->dispatch(new WriteEntityFactory($addon, $slug, $namespace));
74
        $this->dispatch(new WriteEntityObserver($addon, $slug, $namespace));
75
        $this->dispatch(new WriteEntityCriteria($addon, $slug, $namespace));
76
        $this->dispatch(new WriteEntityPresenter($addon, $slug, $namespace));
77
        $this->dispatch(new WriteEntityController($addon, $slug, $namespace));
78
        $this->dispatch(new WriteEntityCollection($addon, $slug, $namespace));
79
        $this->dispatch(new WriteEntityRepository($addon, $slug, $namespace));
80
        $this->dispatch(new WriteEntityFormBuilder($addon, $slug, $namespace));
81
        $this->dispatch(new WriteEntityTableBuilder($addon, $slug, $namespace));
82
        $this->dispatch(new WriteEntityModelInterface($addon, $slug, $namespace));
83
        $this->dispatch(new WriteEntityRepositoryInterface($addon, $slug, $namespace));
84
85
        // Run this last since it scans the above.
86
        $this->dispatch(new WriteEntityTestCases($addon, $slug, $namespace));
87
88
        $this->call(
89
            'make:migration',
90
            [
91
                'name'     => 'create_' . $slug . '_stream',
92
                '--addon'  => $addon->getNamespace(),
93
                '--stream' => $slug,
94
            ]
95
        );
96
    }
97
98
    /**
99
     * Get the console command arguments.
100
     *
101
     * @return array
102
     */
103
    protected function getArguments()
104
    {
105
        return [
106
            ['slug', InputArgument::REQUIRED, 'The entity\'s stream slug.'],
107
            ['addon', InputArgument::REQUIRED, 'The addon in which to put the new entity namespace.'],
108
        ];
109
    }
110
111
    /**
112
     * Get the console command options.
113
     *
114
     * @return array
115
     */
116 View Code Duplication
    protected function getOptions()
0 ignored issues
show
Duplication introduced by
This method 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...
117
    {
118
        return [
119
            ['namespace', null, InputOption::VALUE_OPTIONAL, 'The stream namespace if not the same as the addon.'],
120
            ['migration', null, InputOption::VALUE_NONE, 'Indicates if an stream migration should be created.'],
121
        ];
122
    }
123
}
124