| Conditions | 7 |
| Paths | 11 |
| Total Lines | 59 |
| Code Lines | 38 |
| 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 |
||
| 106 | public function run(TaskSchedule $task_schedule): bool |
||
| 107 | { |
||
| 108 | if ($this->module === null) { |
||
| 109 | return false; |
||
| 110 | } |
||
| 111 | |||
| 112 | $res = true; |
||
| 113 | |||
| 114 | // Compute the number of days to compute |
||
| 115 | $interval_lastrun = $task_schedule->lastRunTime()->diffAsCarbonInterval(CarbonImmutable::now()); |
||
| 116 | $interval_frequency = CarbonInterval::minutes($task_schedule->frequency()); |
||
| 117 | $interval = $interval_lastrun->greaterThan($interval_frequency) ? $interval_lastrun : $interval_frequency; |
||
| 118 | $nb_days = (int) $interval->ceilDay()->totalDays; |
||
| 119 | |||
| 120 | $view_params_site = [ |
||
| 121 | 'nb_days' => $nb_days, |
||
| 122 | 'upgrade_available' => $this->upgrade_service->isUpgradeAvailable(), |
||
| 123 | 'latest_version' => $this->upgrade_service->latestVersion(), |
||
| 124 | 'download_url' => $this->upgrade_service->downloadUrl(), |
||
| 125 | 'all_users' => $this->user_service->all(), |
||
| 126 | 'unapproved' => $this->user_service->unapproved(), |
||
| 127 | 'unverified' => $this->user_service->unverified(), |
||
| 128 | ]; |
||
| 129 | |||
| 130 | foreach ($this->tree_service->all() as $tree) { |
||
| 131 | /** @var Tree $tree */ |
||
| 132 | |||
| 133 | if ($tree->getPreference(self::TREE_PREFERENCE_NAME) !== '1') { |
||
| 134 | continue; |
||
| 135 | } |
||
| 136 | |||
| 137 | $webmaster = $this->user_service->find((int) $tree->getPreference('WEBMASTER_USER_ID')); |
||
| 138 | if ($webmaster === null) { |
||
| 139 | continue; |
||
| 140 | } |
||
| 141 | I18N::init($webmaster->getPreference('language')); |
||
| 142 | |||
| 143 | $error_logs = $this->healthcheck_service->errorLogs($tree, $nb_days); |
||
| 144 | $nb_errors = $error_logs->sum('nblogs'); |
||
| 145 | |||
| 146 | $view_params = $view_params_site + [ |
||
| 147 | 'tree' => $tree, |
||
| 148 | 'total_by_type' => $this->healthcheck_service->countByRecordType($tree), |
||
| 149 | 'change_by_type' => $this->healthcheck_service->changesByRecordType($tree, $nb_days), |
||
| 150 | 'error_logs' => $error_logs, |
||
| 151 | 'nb_errors' => $nb_errors |
||
| 152 | ]; |
||
| 153 | |||
| 154 | $res = $res && $this->email_service->send( |
||
| 155 | new TreeUser($tree), |
||
| 156 | $webmaster, |
||
| 157 | new NoReplyUser(), |
||
| 158 | I18N::translate('Health Check Report') . ' - ' . I18N::translate('Tree %s', $tree->name()), |
||
| 159 | view($this->module->name() . '::tasks/healthcheck/email-healthcheck-text', $view_params), |
||
| 160 | view($this->module->name() . '::tasks/healthcheck/email-healthcheck-html', $view_params) |
||
| 161 | ); |
||
| 162 | } |
||
| 163 | |||
| 164 | return $res; |
||
| 165 | } |
||
| 206 |