Conditions | 8 |
Paths | 2 |
Total Lines | 61 |
Code Lines | 47 |
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 |
||
56 | public function handle(ServerRequestInterface $request): ResponseInterface |
||
57 | { |
||
58 | if ($this->module === null) { |
||
59 | throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
||
60 | } |
||
61 | |||
62 | $module = $this->module; |
||
63 | $module_name = $this->module->name(); |
||
64 | return Registry::responseFactory()->response(['data' => $this->taskschedules_service->all(true, true) |
||
65 | ->map(function (TaskSchedule $schedule) use ($module, $module_name): array { |
||
66 | $task = $this->taskschedules_service->findTask($schedule->taskId()); |
||
67 | $task_name = $task !== null ? $task->name() : I18N::translate('Task not found'); |
||
68 | $last_run_timestamp = Registry::timestampFactory()->make($schedule->lastRunTime()->getTimestamp()); |
||
69 | |||
70 | return [ |
||
71 | 'edit' => view($module_name . '::admin/tasks-table-options', [ |
||
72 | 'task_sched_id' => $schedule->id(), |
||
73 | 'task_sched_enabled' => $schedule->isEnabled(), |
||
74 | 'task_edit_route' => route(TaskEditPage::class, ['task' => $schedule->id()]), |
||
75 | 'task_status_route' => route(TaskStatusAction::class, [ |
||
76 | 'task' => $schedule->id(), |
||
77 | 'enable' => $schedule->isEnabled() ? 0 : 1 |
||
78 | ]) |
||
79 | ]), |
||
80 | 'status' => [ |
||
81 | 'display' => view($module_name . '::components/yes-no-icons', [ |
||
82 | 'yes' => $schedule->isEnabled() |
||
83 | ]), |
||
84 | 'raw' => $schedule->isEnabled() ? 1 : 0 |
||
85 | ], |
||
86 | 'task_name' => [ |
||
87 | 'display' => '<bdi>' . e($task_name) . '</bdi>', |
||
88 | 'raw' => $task_name |
||
89 | ], |
||
90 | 'last_run' => [ |
||
91 | 'display' => $last_run_timestamp->timestamp() === 0 ? |
||
92 | view('components/datetime', ['timestamp' => $last_run_timestamp]) : |
||
93 | view('components/datetime-diff', ['timestamp' => $last_run_timestamp]), |
||
94 | 'raw' => $schedule->lastRunTime()->getTimestamp() |
||
95 | ], |
||
96 | 'last_result' => [ |
||
97 | 'display' => view($module_name . '::components/yes-no-icons', [ |
||
98 | 'yes' => $schedule->wasLastRunSuccess() |
||
99 | ]), |
||
100 | 'raw' => $schedule->wasLastRunSuccess() ? 1 : 0 |
||
101 | ], |
||
102 | 'frequency' => |
||
103 | '<bdi>' . e(CarbonInterval::minutes($schedule->frequency())->cascade()->forHumans()) . '</bdi>', |
||
104 | 'nb_occurrences' => $schedule->remainingOccurrences() > 0 ? |
||
105 | I18N::number($schedule->remainingOccurrences()) : |
||
106 | I18N::translate('Unlimited'), |
||
107 | 'running' => view($module_name . '::components/yes-no-icons', [ |
||
108 | 'yes' => $schedule->isRunning(), |
||
109 | 'text_yes' => I18N::translate('Running'), |
||
110 | 'text_no' => I18N::translate('Not running') |
||
111 | ]), |
||
112 | 'run' => view($module_name . '::admin/tasks-table-run', [ |
||
113 | 'task_sched_id' => $schedule->id(), |
||
114 | 'run_route' => route(TaskTrigger::class, [ |
||
115 | 'task' => $schedule->taskId(), |
||
116 | 'force' => $module->getPreference('MAJ_AT_FORCE_EXEC_TOKEN') |
||
117 | ]) |
||
124 |