Completed
Push — master ( e09f8c...50fa0d )
by Fumio
10:35
created

AddonRemoveCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 13.21 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B handle() 7 23 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
    /**
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 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...
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