Completed
Push — master ( 880a30...6b3c1e )
by Fumio
02:31
created

AddonRemoveCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 91.67%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 4
c 2
b 0
f 1
lcom 1
cbo 3
dl 0
loc 53
ccs 11
cts 12
cp 0.9167
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B handle() 0 23 4
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
    /**
13
     * The console command signature.
14
     *
15
     * @var string
16
     */
17
    protected $signature = 'addon:remove
18
        {name : Name of addon.}
19
        {--force : Force remove.}
20
    ';
21
22
    /**
23
     * The console command description.
24
     *
25
     * @var string
26
     */
27
    protected $description = 'Remove addon.';
28
29
    /**
30
     * @var \Illuminate\Filesystem\Filesystem
31
     */
32
    protected $filesystem;
33
34
    /**
35
     * Execute the console command.
36
     *
37
     * @return mixed
38
     */
39 3
    public function handle(Filesystem $filesystem, AddonEnvironment $env)
40
    {
41 3
        $addonName = $this->argument('name');
42
43
        // check addon
44 3
        if (!$env->exists($addonName)) {
0 ignored issues
show
Bug introduced by
It seems like $addonName defined by $this->argument('name') on line 41 can also be of type array; however, Jumilla\Addomnipot\Laravel\Environment::exists() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
45 1
            throw new UnexpectedValueException(sprintf('Addon "%s" is not found.', $addonName));
46
        }
47
48
        // confirm
49 2
        if (!$this->option('force')) {
50 1
            if (!$this->confirm('Are you sure? [y/N]', false)) {
51 1
                $this->comment('canceled');
52
53 1
                return;
54
            }
55
        }
56
57
        // process
58 1
        $filesystem->deleteDirectory($env->path($addonName));
0 ignored issues
show
Bug introduced by
It seems like $addonName defined by $this->argument('name') on line 41 can also be of type array; however, Jumilla\Addomnipot\Laravel\Environment::path() does only seem to accept string|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
59
60 1
        $this->info(sprintf('Addon "%s" removed.', $addonName));
61 1
    }
62
}
63