| Conditions | 4 |
| Paths | 4 |
| Total Lines | 36 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 26 | public function process(TaskTypeInterface $task) |
||
| 27 | { |
||
| 28 | $taskResult = new TaskResult(); |
||
| 29 | |||
| 30 | try { |
||
| 31 | $driver = $this->driverFactory->getDriverForTask($task); |
||
| 32 | } catch (TaskException $e) { |
||
| 33 | $exceptionMessage = sprintf("TaskException: %s", $e->getMessage()); |
||
| 34 | $taskResult->setSuccess(false) |
||
| 35 | ->setErrors([$exceptionMessage]) |
||
| 36 | ; |
||
| 37 | return $taskResult; |
||
| 38 | } |
||
| 39 | |||
| 40 | |||
| 41 | //See if there's any issues with the tasks before running. |
||
| 42 | $validationErrors = $driver->canRun($task); |
||
| 43 | if (count($validationErrors) > 0) { |
||
| 44 | $taskResult->setSuccess(false) |
||
| 45 | ->setErrors($validationErrors) |
||
|
|
|||
| 46 | ; |
||
| 47 | return $taskResult; |
||
| 48 | } |
||
| 49 | |||
| 50 | //Run the task, and then check for errors |
||
| 51 | $errors = $driver->run($task); |
||
| 52 | if (count($errors) > 0) { |
||
| 53 | $taskResult->setSuccess(false) |
||
| 54 | ->setErrors($errors) |
||
| 55 | ; |
||
| 56 | return $taskResult; |
||
| 57 | } |
||
| 58 | |||
| 59 | $taskResult->setSuccess(true); |
||
| 60 | return $taskResult; |
||
| 61 | } |
||
| 62 | } |
||
| 63 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.