Completed
Push — master ( d3a073...5737c8 )
by Greg
02:21
created

src/Task/Bower/Base.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
namespace Robo\Task\Bower;
3
4
use Robo\Task\BaseTask;
5
use Robo\Exception\TaskException;
6
7
abstract class Base extends BaseTask
8
{
9
    use \Robo\Common\ExecOneCommand;
10
11
    protected $opts = [];
12
    protected $action = '';
13
14
    /**
15
     * @var string
16
     */
17
    protected $command = '';
18
19
    /**
20
     * adds `allow-root` option to bower
21
     *
22
     * @return $this
23
     */
24
    public function allowRoot()
25
    {
26
        $this->option('allow-root');
27
        return $this;
28
    }
29
30
    /**
31
     * adds `force-latest` option to bower
32
     *
33
     * @return $this
34
     */
35
    public function forceLatest()
36
    {
37
        $this->option('force-latest');
38
        return $this;
39
    }
40
41
    /**
42
     * adds `production` option to bower
43
     *
44
     * @return $this
45
     */
46
    public function noDev()
47
    {
48
        $this->option('production');
49
        return $this;
50
    }
51
52
    /**
53
     * adds `offline` option to bower
54
     *
55
     * @return $this
56
     */
57
    public function offline()
58
    {
59
        $this->option('offline');
60
        return $this;
61
    }
62
63
    /**
64
     * Base constructor.
65
     *
66
     * @param null|string $pathToBower
67
     *
68
     * @throws \Robo\Exception\TaskException
69
     */
70 View Code Duplication
    public function __construct($pathToBower = null)
71
    {
72
        $this->command = $pathToBower;
73
        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...
74
            $this->command = $this->findExecutable('bower');
75
        }
76
        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...
77
            throw new TaskException(__CLASS__, "Bower executable not found.");
78
        }
79
    }
80
81
    /**
82
     * @return string
83
     */
84
    public function getCommand()
85
    {
86
        return "{$this->command} {$this->action}{$this->arguments}";
87
    }
88
}
89