| Conditions | 8 |
| Paths | 2 |
| Total Lines | 60 |
| Code Lines | 46 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 55 | public function handle(ServerRequestInterface $request): ResponseInterface |
||
| 56 | { |
||
| 57 | if ($this->module === null) { |
||
| 58 | throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
||
| 59 | } |
||
| 60 | |||
| 61 | $module = $this->module; |
||
| 62 | $module_name = $this->module->name(); |
||
| 63 | return response(['data' => $this->taskschedules_service->all(true, true) |
||
| 64 | ->map(function (TaskSchedule $schedule) use ($module, $module_name): array { |
||
| 65 | $task = $this->taskschedules_service->findTask($schedule->taskId()); |
||
| 66 | $task_name = $task !== null ? $task->name() : I18N::translate('Task not found'); |
||
| 67 | |||
| 68 | return [ |
||
| 69 | 'edit' => view($module_name . '::admin/tasks-table-options', [ |
||
| 70 | 'task_sched_id' => $schedule->id(), |
||
| 71 | 'task_sched_enabled' => $schedule->isEnabled(), |
||
| 72 | 'task_edit_route' => route(TaskEditPage::class, ['task' => $schedule->id()]), |
||
| 73 | 'task_status_route' => route(TaskStatusAction::class, [ |
||
| 74 | 'task' => $schedule->id(), |
||
| 75 | 'enable' => $schedule->isEnabled() ? 0 : 1 |
||
| 76 | ]) |
||
| 77 | ]), |
||
| 78 | 'status' => [ |
||
| 79 | 'display' => view($module_name . '::components/yes-no-icons', [ |
||
| 80 | 'yes' => $schedule->isEnabled() |
||
| 81 | ]), |
||
| 82 | 'raw' => $schedule->isEnabled() ? 1 : 0 |
||
| 83 | ], |
||
| 84 | 'task_name' => [ |
||
| 85 | 'display' => '<bdi>' . e($task_name) . '</bdi>', |
||
| 86 | 'raw' => $task_name |
||
| 87 | ], |
||
| 88 | 'last_run' => [ |
||
| 89 | 'display' => $schedule->lastRunTime()->timestamp() === 0 ? |
||
| 90 | view('components/datetime', ['timestamp' => $schedule->lastRunTime()]) : |
||
| 91 | view('components/datetime-diff', ['timestamp' => $schedule->lastRunTime()]), |
||
| 92 | 'raw' => $schedule->lastRunTime()->timestamp() |
||
| 93 | ], |
||
| 94 | 'last_result' => [ |
||
| 95 | 'display' => view($module_name . '::components/yes-no-icons', [ |
||
| 96 | 'yes' => $schedule->wasLastRunSuccess() |
||
| 97 | ]), |
||
| 98 | 'raw' => $schedule->wasLastRunSuccess() ? 1 : 0 |
||
| 99 | ], |
||
| 100 | 'frequency' => |
||
| 101 | '<bdi>' . e(CarbonInterval::minutes($schedule->frequency())->cascade()->forHumans()) . '</bdi>', |
||
| 102 | 'nb_occurrences' => $schedule->remainingOccurrences() > 0 ? |
||
| 103 | I18N::number($schedule->remainingOccurrences()) : |
||
| 104 | I18N::translate('Unlimited'), |
||
| 105 | 'running' => view($module_name . '::components/yes-no-icons', [ |
||
| 106 | 'yes' => $schedule->isRunning(), |
||
| 107 | 'text_yes' => I18N::translate('Running'), |
||
| 108 | 'text_no' => I18N::translate('Not running') |
||
| 109 | ]), |
||
| 110 | 'run' => view($module_name . '::admin/tasks-table-run', [ |
||
| 111 | 'task_sched_id' => $schedule->id(), |
||
| 112 | 'run_route' => route(TaskTrigger::class, [ |
||
| 113 | 'task' => $schedule->taskId(), |
||
| 114 | 'force' => $module->getPreference('MAJ_AT_FORCE_EXEC_TOKEN') |
||
| 115 | ]) |
||
| 122 |