Conditions | 7 |
Paths | 11 |
Total Lines | 59 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
127 | public function run(TaskSchedule $task_schedule): bool |
||
128 | { |
||
129 | if ($this->module === null) { |
||
130 | return false; |
||
131 | } |
||
132 | |||
133 | $res = true; |
||
134 | |||
135 | // Compute the number of days to compute |
||
136 | $interval_lastrun = $task_schedule->lastRunTime()->diffAsCarbonInterval(Carbon::now()); |
||
137 | //@phpcs:ignore Generic.Files.LineLength.TooLong |
||
138 | $interval = $interval_lastrun->greaterThan($task_schedule->frequency()) ? $interval_lastrun : $task_schedule->frequency(); |
||
139 | $nb_days = (int) $interval->ceilDay()->totalDays; |
||
140 | |||
141 | $view_params_site = [ |
||
142 | 'nb_days' => $nb_days, |
||
143 | 'upgrade_available' => $this->upgrade_service->isUpgradeAvailable(), |
||
144 | 'latest_version' => $this->upgrade_service->latestVersion(), |
||
145 | 'download_url' => $this->upgrade_service->downloadUrl(), |
||
146 | 'all_users' => $this->user_service->all(), |
||
147 | 'unapproved' => $this->user_service->unapproved(), |
||
148 | 'unverified' => $this->user_service->unverified(), |
||
149 | ]; |
||
150 | |||
151 | foreach ($this->tree_service->all() as $tree) { |
||
152 | /** @var Tree $tree */ |
||
153 | |||
154 | if ($tree->getPreference(self::TREE_PREFERENCE_NAME) !== '1') { |
||
155 | continue; |
||
156 | } |
||
157 | |||
158 | $webmaster = $this->user_service->find((int) $tree->getPreference('WEBMASTER_USER_ID')); |
||
159 | if ($webmaster === null) { |
||
160 | continue; |
||
161 | } |
||
162 | I18N::init($webmaster->getPreference('language')); |
||
163 | |||
164 | $error_logs = $this->healthcheck_service->errorLogs($tree, $nb_days); |
||
165 | $nb_errors = $error_logs->sum('nblogs'); |
||
166 | |||
167 | $view_params = array_merge($view_params_site, [ |
||
168 | 'tree' => $tree, |
||
169 | 'total_by_type' => $this->healthcheck_service->countByRecordType($tree), |
||
170 | 'change_by_type' => $this->healthcheck_service->changesByRecordType($tree, $nb_days), |
||
171 | 'error_logs' => $error_logs, |
||
172 | 'nb_errors' => $nb_errors |
||
173 | ]); |
||
174 | |||
175 | $res = $res && $this->email_service->send( |
||
176 | new TreeUser($tree), |
||
177 | $webmaster, |
||
178 | new NoReplyUser(), |
||
179 | I18N::translate('Health Check Report') . ' - ' . I18N::translate('Tree %s', $tree->name()), |
||
180 | view($this->module->name() . '::tasks/healthcheck/email-healthcheck-text', $view_params), |
||
181 | view($this->module->name() . '::tasks/healthcheck/email-healthcheck-html', $view_params) |
||
182 | ); |
||
183 | } |
||
184 | |||
185 | return $res; |
||
186 | } |
||
227 |