Base::getCommand()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Robo\Task\Gulp;
4
5
use Robo\Task\BaseTask;
6
use Robo\Exception\TaskException;
7
use Robo\Common\ProcessUtils;
8
9
abstract class Base extends BaseTask
10
{
11
    use \Robo\Common\ExecOneCommand;
12
13
    /**
14
     * @var string
15
     */
16
    protected $command = '';
17
18
    /**
19
     * @var array
20
     */
21
    protected $opts = [];
22
23
    /**
24
     * @var string
25
     */
26
    protected $task = '';
27
28
    /**
29
     * adds `silent` option to gulp
30
     *
31
     * @return $this
32
     */
33
    public function silent()
34
    {
35
        $this->option('silent');
36
        return $this;
37
    }
38
39
    /**
40
     * adds `--no-color` option to gulp
41
     *
42
     * @return $this
43
     */
44
    public function noColor()
45
    {
46
        $this->option('no-color');
47
        return $this;
48
    }
49
50
    /**
51
     * adds `--color` option to gulp
52
     *
53
     * @return $this
54
     */
55
    public function color()
56
    {
57
        $this->option('color');
58
        return $this;
59
    }
60
61
    /**
62
     * adds `--tasks-simple` option to gulp
63
     *
64
     * @return $this
65
     */
66
    public function simple()
67
    {
68
        $this->option('tasks-simple');
69
        return $this;
70
    }
71
72
    /**
73
     * @param string $task
74
     * @param null|string $pathToGulp
75
     *
76
     * @throws \Robo\Exception\TaskException
77
     */
78 View Code Duplication
    public function __construct($task, $pathToGulp = null)
0 ignored issues
show
Duplication introduced by
This method 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...
79
    {
80
        $this->task = $task;
81
        $this->command = $pathToGulp;
82
        if (!$this->command) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->command of type null|string is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
83
            $this->command = $this->findExecutable('gulp');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->findExecutable('gulp') can also be of type false. However, the property $command is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
84
        }
85
        if (!$this->command) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->command of type string|false is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
86
            throw new TaskException(__CLASS__, "Gulp executable not found.");
87
        }
88
    }
89
90
    /**
91
     * @return string
92
     */
93
    public function getCommand()
94
    {
95
        return "{$this->command} " . ProcessUtils::escapeArgument($this->task) . "{$this->arguments}";
0 ignored issues
show
Deprecated Code introduced by
The method Robo\Common\ProcessUtils::escapeArgument() has been deprecated with message: since version 3.3, to be removed in 4.0. Use a command line array or give env vars to the `Process::start/run()` method instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
96
    }
97
}
98