| Conditions | 19 |
| Paths | 9226 |
| Total Lines | 86 |
| Code Lines | 62 |
| 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 |
||
| 113 | $lastrun = date($f, $task->getLastExecTime()); |
||
| 114 | |||
| 115 | $f = 'H:i:s'; |
||
| 116 | $trigger = $task->getNextTriggerTime(); |
||
| 117 | if ($trigger - time() > 86400) { |
||
| 118 | $f = 'Y-m-d H:i:s'; |
||
| 119 | } |
||
| 120 | |||
| 121 | if (($user = $task->getUserName()) == null) { |
||
| 122 | $user = $module->getDefaultUserName(); |
||
| 123 | } |
||
| 124 | $nextrun = date($f, $trigger) . ($task->getIsPending() ? '*' : ''); |
||
| 125 | if ($task->getIsPending()) { |
||
| 126 | $nextrun = $this->_outWriter->format($nextrun, [TShellWriter::GREEN, TShellWriter::BOLD]); |
||
| 127 | } |
||
| 128 | |||
| 129 | $rows[] = [$task->getName(), $task->getSchedule(), $task->getTask(), $lastrun, $nextrun, '@' . $user, $task->getProcessCount()]; |
||
| 130 | } |
||
| 131 | $this->_outWriter->write($this->_outWriter->tableWidget(['headers' => ['Name', 'Schedule', 'Task', 'Last Run', 'Next Run', 'User', 'Run #'], |
||
| 132 | 'rows' => $rows])); |
||
| 133 | $this->_outWriter->writeLine("\nAny 'next run' with a * means it is Pending\n"); |
||
| 134 | |||
| 135 | return true; |
||
| 136 | } |
||
| 137 | |||
| 138 | /** |
||
| 139 | * shows the registered tasks from the application for possible configuration |
||
| 140 | * or addition to TDbCronModule. |
||
| 141 | * @param TCronModule $module the module servicing the action |
||
| 142 | * @param mixed $args |
||
| 143 | */ |
||
| 144 | public function actionIndex($args) |
||
| 145 | { |
||
| 146 | $module = $this->getCronModule(); |
||
| 147 | |||
| 148 | $infos = $module->getTaskInfos(true); |
||
| 149 | $this->_outWriter->writeLine(); |
||
| 150 | $this->_outWriter->writeLine(" Registered Cron Task Information: ", [TShellWriter::BOLD]); |
||
| 151 | if (!count($infos)) { |
||
| 152 | $this->_outWriter->writeLine(" (** No registered application tasks **)"); |
||
| 153 | return true; |
||
| 154 | } |
||
| 155 | $rows = []; |
||
| 156 | foreach ($infos as $taskinfo) { |
||
| 157 | $rows[] = [ |
||
| 158 | $this->_outWriter->format($taskinfo->getName(), [TShellWriter::BLUE, TShellWriter::BOLD]), |
||
| 159 | $taskinfo->getTask(), $taskinfo->getModuleId(), $taskinfo->getTitle() |
||
| 160 | ]; |
||
| 161 | $rows[] = ['span' => $this->_outWriter->format(' ' . $taskinfo->getDescription(), TShellWriter::DARK_GRAY)]; |
||
| 162 | } |
||
| 163 | $this->_outWriter->write($this->_outWriter->tableWidget(['headers' => ['Task ID', 'Task', 'Module ID', 'Title'], |
||
| 164 | 'rows' => $rows])); |
||
| 165 | $this->_outWriter->writeLine(); |
||
| 166 | return true; |
||
| 167 | } |
||
| 168 | } |
||
| 169 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.