Completed
Pull Request — master (#11)
by
unknown
02:46
created

UpdateCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 63
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 93.75%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 63
loc 63
ccs 15
cts 16
cp 0.9375
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 8 8 1
A getInitializerInstance() 4 4 1
A title() 4 4 1
A getOptionsConfig() 11 11 2

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 MadWeb\Initializer\Console\Commands;
4
5
use Illuminate\Contracts\Container\Container;
6
7 View Code Duplication
class UpdateCommand extends AbstractInitializeCommand
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...
8
{
9
    /**
10
     * The console command name.
11
     *
12
     * @var string
13
     */
14
    protected $name = 'app:update';
15
16
    /**
17
     * The console command description.
18
     *
19
     * @var string
20
     */
21
    protected $description = 'Update the application according to current environment';
22
23
    /**
24
     * Create a new command instance.
25
     *
26
     * @param  Illuminate\Contracts\Container\Container  $container
27
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
28
     */
29 30
    public function __construct(Container $container)
30
    {
31 30
        $this->signature = 'app:update
32
                            {--root : Run commands which requires root privileges}
33 30
                            {--o|options=* : Run commands for custom options'.$this->getOptionsConfig($container).'}';
34
35 30
        parent::__construct();
36 30
    }
37
38
    /**
39
     * Returns instance of Update class which defines initializing runner chain.
40
     *
41
     * {@inheritdoc}
42
     */
43 15
    protected function getInitializerInstance(Container $container)
44
    {
45 15
        return $container->make('app.updater');
46
    }
47
48 15
    protected function title(): string
49
    {
50 15
        return 'Application update';
51
    }
52
53
    /**
54
     * Returns allowed options.
55
     *
56
     * @return string
57
     */
58 30
    protected function getOptionsConfig(Container $container)
59
    {
60 30
        $config = $container->make('config');
61 30
        $options = $config->get($config->get('initializer.options.update'));
62
63 30
        $options = array_keys($options);
64
65 30
        if (count($options) > 0) {
66
            return '. Allowed options:['.implode(', ', $options).']';
67
        }
68 30
    }
69
}
70