This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Robo\Task\Testing; |
||
4 | |||
5 | use Robo\Contract\CommandInterface; |
||
6 | use Robo\Contract\PrintedInterface; |
||
7 | use Robo\Task\BaseTask; |
||
8 | |||
9 | /** |
||
10 | * Executes Behat tests |
||
11 | * |
||
12 | * ``` php |
||
13 | * <?php |
||
14 | * $this->taskBehat() |
||
15 | * ->format('pretty') |
||
16 | * ->noInteraction() |
||
17 | * ->run(); |
||
18 | * ?> |
||
19 | * ``` |
||
20 | * |
||
21 | */ |
||
22 | class Behat extends BaseTask implements CommandInterface, PrintedInterface |
||
23 | { |
||
24 | use \Robo\Common\ExecOneCommand; |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $command; |
||
30 | |||
31 | /** |
||
32 | * @var string[] $formaters available formaters for format option |
||
33 | */ |
||
34 | protected $formaters = ['progress', 'pretty', 'junit']; |
||
35 | |||
36 | /** |
||
37 | * @var string[] $verbose_levels available verbose levels |
||
38 | */ |
||
39 | protected $verbose_levels = ['v', 'vv']; |
||
40 | |||
41 | /** |
||
42 | * Behat constructor. |
||
43 | * |
||
44 | * @param null|string $pathToBehat |
||
45 | * |
||
46 | * @throws \Robo\Exception\TaskException |
||
47 | */ |
||
48 | View Code Duplication | public function __construct($pathToBehat = null) |
|
0 ignored issues
–
show
|
|||
49 | { |
||
50 | $this->command = $pathToBehat; |
||
51 | if (!$this->command) { |
||
0 ignored issues
–
show
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 For '' == false // true
'' == null // true
'ab' == false // false
'ab' == null // false
// It is often better to use strict comparison
'' === false // false
'' === null // false
Loading history...
|
|||
52 | $this->command = $this->findExecutable('behat'); |
||
0 ignored issues
–
show
It seems like
$this->findExecutable('behat') 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 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...
|
|||
53 | } |
||
54 | if (!$this->command) { |
||
0 ignored issues
–
show
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 For '' == false // true
'' == null // true
'ab' == false // false
'ab' == null // false
// It is often better to use strict comparison
'' === false // false
'' === null // false
Loading history...
|
|||
55 | throw new \Robo\Exception\TaskException(__CLASS__, "Neither composer nor phar installation of Behat found"); |
||
56 | } |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * @return $this |
||
61 | */ |
||
62 | public function stopOnFail() |
||
63 | { |
||
64 | $this->option('stop-on-failure'); |
||
65 | return $this; |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * @return $this |
||
70 | */ |
||
71 | public function noInteraction() |
||
72 | { |
||
73 | $this->option('no-interaction'); |
||
74 | return $this; |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * @param string $config_file |
||
79 | * |
||
80 | * @return $this |
||
81 | */ |
||
82 | public function config($config_file) |
||
83 | { |
||
84 | $this->option('config', $config_file); |
||
85 | return $this; |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * @return $this |
||
90 | */ |
||
91 | public function colors() |
||
92 | { |
||
93 | $this->option('colors'); |
||
94 | return $this; |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * @return $this |
||
99 | */ |
||
100 | public function noColors() |
||
101 | { |
||
102 | $this->option('no-colors'); |
||
103 | return $this; |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * @param string $suite |
||
108 | * |
||
109 | * @return $this |
||
110 | */ |
||
111 | public function suite($suite) |
||
112 | { |
||
113 | $this->option('suite', $suite); |
||
114 | return $this; |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * @param string $level |
||
119 | * |
||
120 | * @return $this |
||
121 | */ |
||
122 | View Code Duplication | public function verbose($level = 'v') |
|
0 ignored issues
–
show
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...
|
|||
123 | { |
||
124 | if (!in_array($level, $this->verbose_levels)) { |
||
125 | throw new \InvalidArgumentException('expected ' . implode(',', $this->verbose_levels)); |
||
126 | } |
||
127 | $this->option('-' . $level); |
||
128 | return $this; |
||
129 | } |
||
130 | |||
131 | /** |
||
132 | * @param string $formater |
||
133 | * |
||
134 | * @return $this |
||
135 | */ |
||
136 | View Code Duplication | public function format($formater) |
|
137 | { |
||
138 | if (!in_array($formater, $this->formaters)) { |
||
139 | throw new \InvalidArgumentException('expected ' . implode(',', $this->formaters)); |
||
140 | } |
||
141 | $this->option('format', $formater); |
||
142 | return $this; |
||
143 | } |
||
144 | |||
145 | /** |
||
146 | * {@inheritdoc} |
||
147 | */ |
||
148 | public function getCommand() |
||
149 | { |
||
150 | return $this->command . $this->arguments; |
||
151 | } |
||
152 | |||
153 | /** |
||
154 | * {@inheritdoc} |
||
155 | */ |
||
156 | public function run() |
||
157 | { |
||
158 | $this->printTaskInfo('Running behat {arguments}', ['arguments' => $this->arguments]); |
||
159 | return $this->executeCommand($this->getCommand()); |
||
160 | } |
||
161 | } |
||
162 |
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.