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 | * Runs PHPUnit tests |
||
11 | * |
||
12 | * ``` php |
||
13 | * <?php |
||
14 | * $this->taskPHPUnit() |
||
15 | * ->group('core') |
||
16 | * ->bootstrap('test/bootstrap.php') |
||
17 | * ->run() |
||
18 | * |
||
19 | * ?> |
||
20 | * ``` |
||
21 | */ |
||
22 | class PHPUnit extends BaseTask implements CommandInterface, PrintedInterface |
||
23 | { |
||
24 | use \Robo\Common\ExecOneCommand; |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $command; |
||
30 | |||
31 | /** |
||
32 | * Directory of test files or single test file to run. Appended to |
||
33 | * the command and arguments. |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $files = ''; |
||
38 | |||
39 | /** |
||
40 | * PHPUnit constructor. |
||
41 | * |
||
42 | * @param null|string $pathToPhpUnit |
||
43 | * |
||
44 | * @throws \Robo\Exception\TaskException |
||
45 | */ |
||
46 | View Code Duplication | public function __construct($pathToPhpUnit = null) |
|
0 ignored issues
–
show
|
|||
47 | { |
||
48 | $this->command = $pathToPhpUnit; |
||
49 | 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
![]() |
|||
50 | $this->command = $this->findExecutablePhar('phpunit'); |
||
0 ignored issues
–
show
It seems like
$this->findExecutablePhar('phpunit') can also be of type boolean . 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;
}
![]() |
|||
51 | } |
||
52 | if (!$this->command) { |
||
53 | throw new \Robo\Exception\TaskException(__CLASS__, "Neither local phpunit nor global composer installation not found"); |
||
54 | } |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * @param string $filter |
||
59 | * |
||
60 | * @return $this |
||
61 | */ |
||
62 | public function filter($filter) |
||
63 | { |
||
64 | $this->option('filter', $filter); |
||
65 | return $this; |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * @param string $group |
||
70 | * |
||
71 | * @return $this |
||
72 | */ |
||
73 | public function group($group) |
||
74 | { |
||
75 | $this->option("group", $group); |
||
76 | return $this; |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * @param string $group |
||
81 | * |
||
82 | * @return $this |
||
83 | */ |
||
84 | public function excludeGroup($group) |
||
85 | { |
||
86 | $this->option("exclude-group", $group); |
||
87 | return $this; |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * adds `log-json` option to runner |
||
92 | * |
||
93 | * @param string $file |
||
94 | * |
||
95 | * @return $this |
||
96 | */ |
||
97 | public function json($file = null) |
||
98 | { |
||
99 | $this->option("log-json", $file); |
||
100 | return $this; |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * adds `log-junit` option |
||
105 | * |
||
106 | * @param string $file |
||
107 | * |
||
108 | * @return $this |
||
109 | */ |
||
110 | public function xml($file = null) |
||
111 | { |
||
112 | $this->option("log-junit", $file); |
||
113 | return $this; |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * @param string $file |
||
118 | * |
||
119 | * @return $this |
||
120 | */ |
||
121 | public function tap($file = "") |
||
122 | { |
||
123 | $this->option("log-tap", $file); |
||
124 | return $this; |
||
125 | } |
||
126 | |||
127 | /** |
||
128 | * @param string $file |
||
129 | * |
||
130 | * @return $this |
||
131 | */ |
||
132 | public function bootstrap($file) |
||
133 | { |
||
134 | $this->option("bootstrap", $file); |
||
135 | return $this; |
||
136 | } |
||
137 | |||
138 | /** |
||
139 | * @param string $file |
||
140 | * |
||
141 | * @return $this |
||
142 | */ |
||
143 | public function configFile($file) |
||
144 | { |
||
145 | $this->option('-c', $file); |
||
146 | return $this; |
||
147 | } |
||
148 | |||
149 | /** |
||
150 | * @return $this |
||
151 | */ |
||
152 | public function debug() |
||
153 | { |
||
154 | $this->option("debug"); |
||
155 | return $this; |
||
156 | } |
||
157 | |||
158 | /** |
||
159 | * Directory of test files or single test file to run. |
||
160 | * |
||
161 | * @param string $files |
||
162 | * A single test file or a directory containing test files. |
||
163 | * |
||
164 | * @return $this |
||
165 | * |
||
166 | * @throws \Robo\Exception\TaskException |
||
167 | * |
||
168 | * @deprecated Use file() or dir() method instead |
||
169 | */ |
||
170 | public function files($files) |
||
171 | { |
||
172 | if (!empty($this->files) || is_array($files)) { |
||
173 | throw new \Robo\Exception\TaskException(__CLASS__, "Only one file or directory may be provided."); |
||
174 | } |
||
175 | $this->files = ' ' . $files; |
||
176 | |||
177 | return $this; |
||
178 | } |
||
179 | |||
180 | /** |
||
181 | * Test the provided file. |
||
182 | * |
||
183 | * @param string $file |
||
184 | * Path to file to test. |
||
185 | * |
||
186 | * @return $this |
||
187 | */ |
||
188 | public function file($file) |
||
189 | { |
||
190 | return $this->files($file); |
||
0 ignored issues
–
show
The method
Robo\Task\Testing\PHPUnit::files() has been deprecated with message: Use file() or dir() 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. ![]() |
|||
191 | } |
||
192 | |||
193 | /** |
||
194 | * {@inheritdoc} |
||
195 | */ |
||
196 | public function getCommand() |
||
197 | { |
||
198 | return $this->command . $this->arguments . $this->files; |
||
199 | } |
||
200 | |||
201 | /** |
||
202 | * {@inheritdoc} |
||
203 | */ |
||
204 | public function run() |
||
205 | { |
||
206 | $this->printTaskInfo('Running PHPUnit {arguments}', ['arguments' => $this->arguments]); |
||
207 | return $this->executeCommand($this->getCommand()); |
||
208 | } |
||
209 | } |
||
210 |
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.