Conditions | 6 |
Paths | 2 |
Total Lines | 68 |
Code Lines | 47 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 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 |
||
70 | public function handle(ServerRequestInterface $request): ResponseInterface |
||
71 | { |
||
72 | if ($this->module === null) { |
||
73 | throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
||
74 | } |
||
75 | |||
76 | $task_schedules = $this->taskschedules_service->all(true, true) |
||
77 | ->map(function (TaskSchedule $value) { |
||
78 | |||
79 | $row = $value->toArray(); |
||
80 | $task = $this->taskschedules_service->findTask($row['task_id']); |
||
81 | $row['task_name'] = $task !== null ? $task->name() : I18N::translate('Task not found'); |
||
82 | return $row; |
||
83 | }); |
||
84 | |||
85 | $search_columns = ['task_name']; |
||
86 | $sort_columns = ['task_name', 'enabled', 'last_run']; |
||
87 | $module_name = $this->module->name(); |
||
88 | |||
89 | $callback = function (array $row) use ($module_name): array { |
||
90 | |||
91 | $row['frequency']->setLocale(I18N::locale()->code()); |
||
92 | |||
93 | $task_options_params = [ |
||
94 | 'task_sched_id' => $row['id'], |
||
95 | 'task_sched_enabled' => $row['enabled'], |
||
96 | 'task_edit_route' => route(TaskEditPage::class, ['task' => $row['id']]), |
||
97 | 'task_status_route' => route(TaskStatusAction::class, [ |
||
98 | 'task' => $row['id'], |
||
99 | 'enable' => $row['enabled'] ? 0 : 1 |
||
100 | ]) |
||
101 | ]; |
||
102 | |||
103 | $task_run_params = [ |
||
104 | 'task_sched_id' => $row['id'], |
||
105 | 'run_route' => route(TaskTrigger::class, [ |
||
106 | 'task' => $row['task_id'], |
||
107 | 'force' => $this->module->getPreference('MAJ_AT_FORCE_EXEC_TOKEN') |
||
108 | ]) |
||
109 | ]; |
||
110 | |||
111 | $datum = [ |
||
112 | view($module_name . '::admin/tasks-table-options', $task_options_params), |
||
113 | view($module_name . '::components/yes-no-icons', ['yes' => $row['enabled']]), |
||
114 | '<span dir="auto">' . e($row['task_name']) . '</span>', |
||
115 | $row['last_run']->unix() === 0 ? |
||
116 | view('components/datetime', ['timestamp' => $row['last_run']]) : |
||
117 | view('components/datetime-diff', ['timestamp' => $row['last_run']]), |
||
118 | view($module_name . '::components/yes-no-icons', ['yes' => $row['last_result']]), |
||
119 | '<span dir="auto">' . e($row['frequency']->cascade()->forHumans()) . '</span>', |
||
120 | $row['nb_occurrences'] > 0 ? I18N::number($row['nb_occurrences']) : I18N::translate('Unlimited'), |
||
121 | view($module_name . '::components/yes-no-icons', [ |
||
122 | 'yes' => $row['is_running'], |
||
123 | 'text_yes' => I18N::translate('Running'), |
||
124 | 'text_no' => I18N::translate('Not running') |
||
125 | ]), |
||
126 | view($module_name . '::admin/tasks-table-run', $task_run_params) |
||
127 | ]; |
||
128 | |||
129 | return $datum; |
||
130 | }; |
||
131 | |||
132 | return $this->datatables_service->handleCollection( |
||
133 | $request, |
||
134 | $task_schedules, |
||
135 | $search_columns, |
||
136 | $sort_columns, |
||
137 | $callback |
||
138 | ); |
||
141 |