Completed
Push — master ( 78b3b4...1185ef )
by Fumio
02:21
created

AddonRemoveCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 60
Duplicated Lines 11.67 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 93.33%

Importance

Changes 0
Metric Value
dl 7
loc 60
ccs 14
cts 15
cp 0.9333
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 4

1 Method

Rating   Name   Duplication   Size   Complexity  
B handle() 7 28 4

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 Jumilla\Addomnipot\Laravel\Console;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Filesystem\Filesystem;
7
use Jumilla\Addomnipot\Laravel\Environment as AddonEnvironment;
8
use UnexpectedValueException;
9
10
class AddonRemoveCommand extends Command
11
{
12
    use Functions;
13
14
    /**
15
     * The console command signature.
16
     *
17
     * @var string
18
     */
19
    protected $signature = 'addon:remove
20
        {addon : Name of addon.}
21
        {--force : Force remove.}
22
    ';
23
24
    /**
25
     * The console command description.
26
     *
27
     * @var string
28
     */
29
    protected $description = 'Remove addon.';
30
31
    /**
32
     * @var \Illuminate\Filesystem\Filesystem
33
     */
34
    protected $filesystem;
35
36
    /**
37
     * Execute the console command.
38
     *
39
     * @return mixed
40
     */
41 3
    public function handle(Filesystem $filesystem, AddonEnvironment $env)
42
    {
43 3
        $addon_name = $this->argument('addon');
44
45 3
        $addon = $env->addon($addon_name);
46
47
        // check addon
48 3
        if ($addon === null) {
49 1
            throw new UnexpectedValueException(sprintf('Addon "%s" is not found.', $addon_name));
50
        }
51
52
        // confirm
53 2
        $this->line('Addon name: '.$addon_name);
54 2
        $this->line('Addon path: '.$addon->relativePath($this->laravel));
55
56 2 View Code Duplication
        if (!$this->option('force')) {
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...
57 1
            if (!$this->confirm('Are you sure? [y/N]', false)) {
58 1
                $this->comment('canceled');
59
60 1
                return;
61
            }
62
        }
63
64
        // process
65 1
        $filesystem->deleteDirectory($addon->path());
66
67 1
        $this->info(sprintf('Addon "%s" removed.', $addon_name));
68 1
    }
69
}
70