Completed
Push — master ( 284085...99e334 )
by Fumio
02:01
created

AddonRemoveCommand::handle()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 28
Code Lines 13

Duplication

Lines 7
Ratio 25 %

Code Coverage

Tests 14
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 13
nc 4
nop 2
dl 7
loc 28
ccs 14
cts 14
cp 1
crap 4
rs 8.5806
c 0
b 0
f 0
1
<?php
2
3
namespace Jumilla\Addomnipot\Laravel\Commands;
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