PublishMigrationCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 61
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 61
loc 61
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fire() 14 14 3
A publish() 7 7 1
A getArguments() 6 6 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
2
3
namespace Consigliere\Components\Commands;
4
5
use Illuminate\Console\Command as ComponentCommand;
6
use Consigliere\Components\Migrations\Migrator;
7
use Consigliere\Components\Publishing\MigrationPublisher;
8
use Symfony\Component\Console\Input\InputArgument;
9
10 View Code Duplication
class PublishMigrationCommand extends ComponentCommand
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...
11
{
12
    /**
13
     * The console command name.
14
     *
15
     * @var string
16
     */
17
    protected $name = 'component:publish-migration';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = "Publish a component's migrations to the application";
25
26
    /**
27
     * Execute the console command.
28
     *
29
     * @return mixed
30
     */
31
    public function fire()
32
    {
33
        if ($name = $this->argument('component')) {
34
            $component = $this->laravel['components']->findOrFail($name);
35
36
            $this->publish($component);
37
38
            return;
39
        }
40
41
        foreach ($this->laravel['components']->enabled() as $component) {
42
            $this->publish($component);
43
        }
44
    }
45
46
    /**
47
     * Publish migration for the specified component.
48
     *
49
     * @param \Consigliere\Components\Component $component
50
     */
51
    public function publish($component)
52
    {
53
        with(new MigrationPublisher(new Migrator($component)))
54
            ->setRepository($this->laravel['components'])
55
            ->setConsole($this)
56
            ->publish();
57
    }
58
59
    /**
60
     * Get the console command arguments.
61
     *
62
     * @return array
63
     */
64
    protected function getArguments()
65
    {
66
        return [
67
            ['component', InputArgument::OPTIONAL, 'The name of component being used.'],
68
        ];
69
    }
70
}
71