1 | <?php |
||
9 | class Result extends ResultData |
||
10 | { |
||
11 | /** |
||
12 | * @var bool |
||
13 | */ |
||
14 | public static $stopOnFail = false; |
||
15 | |||
16 | /** |
||
17 | * @var \Robo\Contract\TaskInterface |
||
18 | */ |
||
19 | protected $task; |
||
20 | |||
21 | /** |
||
22 | * @param \Robo\Contract\TaskInterface $task |
||
23 | * @param int $exitCode |
||
24 | * @param string $message |
||
25 | * @param array $data |
||
26 | */ |
||
27 | public function __construct(TaskInterface $task, $exitCode, $message = '', $data = []) |
||
28 | { |
||
29 | parent::__construct($exitCode, $message, $data); |
||
30 | $this->task = $task; |
||
31 | $this->printResult(); |
||
32 | |||
33 | if (self::$stopOnFail) { |
||
34 | $this->stopOnFail(); |
||
35 | } |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * Tasks should always return a Result. However, they are also |
||
40 | * allowed to return NULL or an array to indicate success. |
||
41 | * |
||
42 | * @param \Robo\Contract\TaskInterface $task |
||
43 | * @param \Robo\Result|\Robo\State\Data|\Robo\ResultData|array|null |
||
44 | * |
||
45 | * @return static |
||
46 | */ |
||
47 | public static function ensureResult($task, $result) |
||
66 | |||
67 | protected function printResult() |
||
82 | |||
83 | /** |
||
84 | * @param \Robo\Contract\TaskInterface $task |
||
85 | * @param string $extension |
||
86 | * @param string $service |
||
87 | * |
||
88 | * @return static |
||
89 | */ |
||
90 | public static function errorMissingExtension(TaskInterface $task, $extension, $service) |
||
97 | |||
98 | /** |
||
99 | * @param \Robo\Contract\TaskInterface $task |
||
100 | * @param string $class |
||
101 | * @param string $package |
||
102 | * |
||
103 | * @return static |
||
104 | */ |
||
105 | public static function errorMissingPackage(TaskInterface $task, $class, $package) |
||
112 | |||
113 | /** |
||
114 | * @param \Robo\Contract\TaskInterface $task |
||
115 | * @param string $message |
||
116 | * @param array $data |
||
117 | * |
||
118 | * @return static |
||
119 | */ |
||
120 | public static function error(TaskInterface $task, $message, $data = []) |
||
124 | |||
125 | /** |
||
126 | * @param \Robo\Contract\TaskInterface $task |
||
127 | * @param \Exception $e |
||
128 | * @param array $data |
||
129 | * |
||
130 | * @return static |
||
131 | */ |
||
132 | public static function fromException(TaskInterface $task, \Exception $e, $data = []) |
||
140 | |||
141 | /** |
||
142 | * @param \Robo\Contract\TaskInterface $task |
||
143 | * @param string $message |
||
144 | * @param array $data |
||
145 | * |
||
146 | * @return static |
||
147 | */ |
||
148 | public static function success(TaskInterface $task, $message = '', $data = []) |
||
152 | |||
153 | /** |
||
154 | * Return a context useful for logging messages. |
||
155 | * |
||
156 | * @return array |
||
157 | */ |
||
158 | public function getContext() |
||
169 | |||
170 | /** |
||
171 | * Add the results from the most recent task to the accumulated |
||
172 | * results from all tasks that have run so far, merging data |
||
173 | * as necessary. |
||
174 | * |
||
175 | * @param int|string $key |
||
176 | * @param \Robo\Result $taskResult |
||
177 | */ |
||
178 | public function accumulate($key, Result $taskResult) |
||
195 | |||
196 | /** |
||
197 | * We assume that named values (e.g. for associative array keys) |
||
198 | * are non-numeric; numeric keys are presumed to simply be the |
||
199 | * index of an array, and therefore insignificant. |
||
200 | * |
||
201 | * @param int|string $key |
||
202 | * |
||
203 | * @return bool |
||
204 | */ |
||
205 | public static function isUnnamed($key) |
||
209 | |||
210 | /** |
||
211 | * @return \Robo\Contract\TaskInterface |
||
212 | */ |
||
213 | public function getTask() |
||
217 | |||
218 | /** |
||
219 | * @return \Robo\Contract\TaskInterface |
||
220 | */ |
||
221 | public function cloneTask() |
||
226 | |||
227 | /** |
||
228 | * @return bool |
||
229 | * |
||
230 | * @deprecated since 1.0. |
||
231 | * |
||
232 | * @see wasSuccessful() |
||
233 | */ |
||
234 | public function __invoke() |
||
239 | |||
240 | /** |
||
241 | * @return $this |
||
242 | */ |
||
243 | public function stopOnFail() |
||
254 | |||
255 | /** |
||
256 | * @param int $status |
||
257 | * |
||
258 | * @throws \Robo\Exception\TaskExitException |
||
259 | */ |
||
260 | private function exitEarly($status) |
||
264 | } |
||
265 |
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()
method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail()
, this method _has_ side-effects. In the following case, we could not remove the method call: