Completed
Push — master ( 0f9065...3b4731 )
by Basenko
8s
created

InitializersMakeCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 55
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 12 2
A getStub() 0 4 1
A getNameInput() 0 4 1
1
<?php
2
3
namespace MadWeb\Initializer\Console\Commands;
4
5
use Illuminate\Console\GeneratorCommand;
6
7
class InitializersMakeCommand extends GeneratorCommand
8
{
9
    /**
10
     * The name and signature of the console command.
11
     *
12
     * @var string
13
     */
14
    protected $signature = 'make:initializers';
15
16
    /**
17
     * The console command description.
18
     *
19
     * @var string
20
     */
21
    protected $description = 'Creates application update and installation config classes.';
22
23
    protected $type = 'Install config';
24
25
    protected $nameInput = 'Install';
26
27
    protected $stubFileName = 'install-config.stub';
28
29 3
    public function handle()
30
    {
31 3
        $installCreateResult = parent::handle();
32
33 3
        $this->nameInput = 'Update';
34 3
        $this->type = 'Update config';
35 3
        $this->stubFileName = 'update-config.stub';
36
37 3
        $updateCreateResult = parent::handle();
38
39 3
        return $installCreateResult and $updateCreateResult;
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
40
    }
41
42
    /**
43
     * Get the stub file for the generator.
44
     *
45
     * @return string
46
     */
47 3
    protected function getStub()
48
    {
49 3
        return __DIR__.'/../../../stubs/'.$this->stubFileName;
50
    }
51
52
    /**
53
     * Get the desired class name from the input.
54
     *
55
     * @return string
56
     */
57 3
    protected function getNameInput()
58
    {
59 3
        return $this->nameInput;
60
    }
61
}
62