| Conditions | 9 |
| Paths | 30 |
| Total Lines | 56 |
| Code Lines | 35 |
| Lines | 13 |
| Ratio | 23.21 % |
| 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 |
||
| 152 | public function save() { |
||
| 153 | $tmp_contrl = new PageController(); |
||
| 154 | |||
| 155 | $tmp_contrl->restrictAccess( |
||
| 156 | Auth::isAdmin() |
||
| 157 | && Filter::checkCsrf() |
||
| 158 | ); |
||
| 159 | |||
| 160 | $task_name = Filter::post('task'); |
||
| 161 | $frequency = Filter::postInteger('frequency'); |
||
| 162 | $is_limited = Filter::postInteger('is_limited', 0, 1); |
||
| 163 | $nb_occur = Filter::postInteger('nb_occur'); |
||
| 164 | |||
| 165 | $task = $this->provider->getTask($task_name, false); |
||
| 166 | |||
| 167 | $success = false; |
||
| 168 | if($task) { |
||
| 169 | $task->setFrequency($frequency); |
||
| 170 | if($is_limited == 1) { |
||
| 171 | $task->setRemainingOccurrences($nb_occur); |
||
| 172 | } |
||
| 173 | else { |
||
| 174 | $task->setRemainingOccurrences(0); |
||
| 175 | } |
||
| 176 | |||
| 177 | $res = $task->save(); |
||
| 178 | |||
| 179 | if($res) { |
||
| 180 | View Code Duplication | if($task instanceof MyArtJaub\Webtrees\Module\AdminTasks\Model\ConfigurableTaskInterface) { |
|
| 181 | $res = $task->saveConfig(); |
||
| 182 | |||
| 183 | if(!$res) { |
||
| 184 | FlashMessages::addMessage(I18N::translate('An error occured while updating the specific settings of administrative task “%s”', $task->getTitle()), 'danger'); |
||
| 185 | Log::addConfigurationLog('Module '.$this->module->getName().' : AdminTask “'. $task->getName() .'” specific settings could not be updated. See error log.'); |
||
| 186 | } |
||
| 187 | } |
||
| 188 | |||
| 189 | View Code Duplication | if($res) { |
|
| 190 | FlashMessages::addMessage(I18N::translate('The administrative task “%s” has been successfully updated', $task->getTitle()), 'success'); |
||
| 191 | Log::addConfigurationLog('Module '.$this->module->getName().' : AdminTask “'.$task->getName() .'” has been updated.'); |
||
| 192 | $success = true; |
||
| 193 | } |
||
| 194 | } |
||
| 195 | else { |
||
| 196 | FlashMessages::addMessage(I18N::translate('An error occured while updating the administrative task “%s”', $task->getTitle()), 'danger'); |
||
| 197 | Log::addConfigurationLog('Module '.$this->module->getName().' : AdminTask “'. $task->getName() .'” could not be updated. See error log.'); |
||
| 198 | } |
||
| 199 | |||
| 200 | } |
||
| 201 | |||
| 202 | $redirection_url = 'module.php?mod=' . $this->module->getName() . '&mod_action=AdminConfig'; |
||
| 203 | if(!$success) { |
||
| 204 | $redirection_url = 'module.php?mod=' . $this->module->getName() . '&mod_action=Task@edit&task='. $task->getName(); |
||
| 205 | } |
||
| 206 | header('Location: ' . WT_BASE_URL . $redirection_url); |
||
| 207 | } |
||
| 208 | |||
| 209 | } |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: