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; |
||
4 | |||
5 | use Robo\Result; |
||
6 | |||
7 | /** |
||
8 | * Extend StackBasedTask to create a Robo task that |
||
9 | * runs a sequence of commands. |
||
10 | * |
||
11 | * This is particularly useful for wrapping an existing |
||
12 | * object-oriented API. Doing it this way requires |
||
13 | * less code than manually adding a method for each wrapped |
||
14 | * function in the delegate. Additionally, wrapping the |
||
15 | * external class in a StackBasedTask creates a loosely-coupled |
||
16 | * interface -- i.e. if a new method is added to the delegate |
||
17 | * class, it is not necessary to update your wrapper, as the |
||
18 | * new functionality will be inherited. |
||
19 | * |
||
20 | * For example, you have: |
||
21 | * |
||
22 | * $frobinator = new Frobinator($a, $b, $c) |
||
23 | * ->friz() |
||
24 | * ->fraz() |
||
25 | * ->frob(); |
||
26 | * |
||
27 | * We presume that the existing library throws an exception on error. |
||
28 | * |
||
29 | * You want: |
||
30 | * |
||
31 | * $result = $this->taskFrobinator($a, $b, $c) |
||
32 | * ->friz() |
||
33 | * ->fraz() |
||
34 | * ->frob() |
||
35 | * ->run(); |
||
36 | * |
||
37 | * Execution is deferred until run(), and a Robo\Result instance is |
||
38 | * returned. Additionally, using Robo will covert Exceptions |
||
39 | * into RoboResult objects. |
||
40 | * |
||
41 | * To create a new Robo task: |
||
42 | * |
||
43 | * - Make a new class that extends StackBasedTask |
||
44 | * - Give it a constructor that creates a new Frobinator |
||
45 | * - Override getDelegate(), and return the Frobinator instance |
||
46 | * |
||
47 | * Finally, add your new class to loadTasks.php as usual, |
||
48 | * and you are all done. |
||
49 | * |
||
50 | * If you need to add any methods to your task that should run |
||
51 | * immediately (e.g. to set parameters used at run() time), just |
||
52 | * implement them in your derived class. |
||
53 | * |
||
54 | * If you need additional methods that should run deferred, just |
||
55 | * define them as 'protected function _foo()'. Then, users may |
||
56 | * call $this->taskFrobinator()->foo() to get deferred execution |
||
57 | * of _foo(). |
||
58 | */ |
||
59 | abstract class StackBasedTask extends BaseTask |
||
60 | { |
||
61 | /** |
||
62 | * @var array |
||
63 | */ |
||
64 | protected $stack = []; |
||
65 | |||
66 | /** |
||
67 | * @var bool |
||
68 | */ |
||
69 | protected $stopOnFail = true; |
||
70 | |||
71 | /** |
||
72 | * @param bool $stop |
||
73 | * |
||
74 | * @return $this |
||
75 | */ |
||
76 | public function stopOnFail($stop = true) |
||
77 | { |
||
78 | $this->stopOnFail = $stop; |
||
79 | return $this; |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * Derived classes should override the getDelegate() method, and |
||
84 | * return an instance of the API class being wrapped. When this |
||
85 | * is done, any method of the delegate is available as a method of |
||
86 | * this class. Calling one of the delegate's methods will defer |
||
87 | * execution until the run() method is called. |
||
88 | * |
||
89 | * @return null|object |
||
90 | */ |
||
91 | protected function getDelegate() |
||
92 | { |
||
93 | return null; |
||
94 | } |
||
95 | |||
96 | /** |
||
97 | * Derived classes that have more than one delegate may override |
||
98 | * getCommandList to add as many delegate commands as desired to |
||
99 | * the list of potential functions that __call() tried to find. |
||
100 | * |
||
101 | * @param string $function |
||
102 | * |
||
103 | * @return array |
||
104 | */ |
||
105 | protected function getDelegateCommandList($function) |
||
106 | { |
||
107 | return [[$this, "_$function"], [$this->getDelegate(), $function]]; |
||
108 | } |
||
109 | |||
110 | /** |
||
111 | * Print progress about the commands being executed |
||
112 | * |
||
113 | * @param string $command |
||
114 | * @param string $action |
||
115 | */ |
||
116 | protected function printTaskProgress($command, $action) |
||
117 | { |
||
118 | $this->printTaskInfo('{command} {action}', ['command' => "{$command[1]}", 'action' => json_encode($action, JSON_UNESCAPED_SLASHES)]); |
||
119 | } |
||
120 | |||
121 | /** |
||
122 | * Derived classes can override processResult to add more |
||
123 | * logic to result handling from functions. By default, it |
||
124 | * is assumed that if a function returns in int, then |
||
125 | * 0 == success, and any other value is the error code. |
||
126 | * |
||
127 | * @param int|\Robo\Result $function_result |
||
128 | * |
||
129 | * @return \Robo\Result |
||
130 | */ |
||
131 | protected function processResult($function_result) |
||
132 | { |
||
133 | if (is_int($function_result)) { |
||
134 | if ($function_result) { |
||
135 | return Result::error($this, $function_result); |
||
136 | } |
||
137 | } |
||
138 | return Result::success($this); |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * Record a function to call later. |
||
143 | * |
||
144 | * @param string $command |
||
145 | * @param array $args |
||
146 | * |
||
147 | * @return $this |
||
148 | */ |
||
149 | protected function addToCommandStack($command, $args) |
||
150 | { |
||
151 | $this->stack[] = array_merge([$command], $args); |
||
152 | return $this; |
||
153 | } |
||
154 | |||
155 | /** |
||
156 | * Any API function provided by the delegate that executes immediately |
||
157 | * may be handled by __call automatically. These operations will all |
||
158 | * be deferred until this task's run() method is called. |
||
159 | * |
||
160 | * @param string $function |
||
161 | * @param array $args |
||
162 | * |
||
163 | * @return $this |
||
164 | */ |
||
165 | public function __call($function, $args) |
||
166 | { |
||
167 | foreach ($this->getDelegateCommandList($function) as $command) { |
||
168 | if (method_exists($command[0], $command[1])) { |
||
169 | // Otherwise, we'll defer calling this function |
||
170 | // until run(), and return $this. |
||
171 | $this->addToCommandStack($command, $args); |
||
0 ignored issues
–
show
|
|||
172 | return $this; |
||
173 | } |
||
174 | } |
||
175 | |||
176 | $message = "Method $function does not exist.\n"; |
||
177 | throw new \BadMethodCallException($message); |
||
178 | } |
||
179 | |||
180 | /** |
||
181 | * @return int |
||
182 | */ |
||
183 | public function progressIndicatorSteps() |
||
184 | { |
||
185 | // run() will call advanceProgressIndicator() once for each |
||
186 | // file, one after calling stopBuffering, and again after compression. |
||
187 | return count($this->stack); |
||
188 | } |
||
189 | |||
190 | /** |
||
191 | * Run all of the queued objects on the stack |
||
192 | * |
||
193 | * @return \Robo\Result |
||
194 | */ |
||
195 | public function run() |
||
196 | { |
||
197 | $this->startProgressIndicator(); |
||
198 | $result = Result::success($this); |
||
199 | |||
200 | foreach ($this->stack as $action) { |
||
201 | $command = array_shift($action); |
||
202 | $this->printTaskProgress($command, $action); |
||
0 ignored issues
–
show
$action is of type array , but the function expects a string .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
203 | $this->advanceProgressIndicator(); |
||
204 | // TODO: merge data from the result on this call |
||
205 | // with data from the result on the previous call? |
||
206 | // For now, the result always comes from the last function. |
||
207 | $result = $this->callTaskMethod($command, $action); |
||
208 | if ($this->stopOnFail && $result && !$result->wasSuccessful()) { |
||
209 | break; |
||
210 | } |
||
211 | } |
||
212 | |||
213 | $this->stopProgressIndicator(); |
||
214 | |||
215 | // todo: add timing information to the result |
||
216 | return $result; |
||
217 | } |
||
218 | |||
219 | /** |
||
220 | * Execute one task method |
||
221 | * |
||
222 | * @param string $command |
||
223 | * @param array $action |
||
224 | * |
||
225 | * @return \Robo\Result |
||
226 | */ |
||
227 | protected function callTaskMethod($command, $action) |
||
228 | { |
||
229 | try { |
||
230 | $function_result = call_user_func_array($command, $action); |
||
231 | return $this->processResult($function_result); |
||
232 | } catch (\Exception $e) { |
||
233 | $this->printTaskError($e->getMessage()); |
||
234 | return Result::fromException($this, $e); |
||
235 | } |
||
236 | } |
||
237 | } |
||
238 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: