| Conditions | 12 |
| Paths | 102 |
| Total Lines | 59 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 105 | public function actionTasks($args) |
||
| 106 | { |
||
| 107 | $module = $this->getCronModule(); |
||
| 108 | |||
| 109 | $time = $module->getLastCronTime(); |
||
| 110 | $this->_outWriter->writeLine("\n Last cron run was " . ($time == 0 ? 'never' : date('Y-m-d H:i:s', (int) $time)) . ""); |
||
| 111 | $this->_outWriter->writeLine("The system time is " . date('Y-m-d H:i:s TP') . "\n"); |
||
| 112 | $tasks = $module->getTasks(); |
||
| 113 | |||
| 114 | $this->_outWriter->writeLine(" Application Cron Tasks: ", [TShellWriter::BOLD]); |
||
| 115 | if (!count($tasks)) { |
||
| 116 | $this->_outWriter->writeLine(" ** There are no configured Cron Tasks. **\n"); |
||
| 117 | return true; |
||
| 118 | } |
||
| 119 | $rows = []; |
||
| 120 | foreach ($tasks as $task) { |
||
| 121 | $lastExecTime = $task->getLastExecTime(); |
||
| 122 | $count = $task->getProcessCount(); |
||
| 123 | if ($lastExecTime === null) { |
||
| 124 | $lastrun = '-'; |
||
| 125 | } else { |
||
| 126 | if (abs(time() - $lastExecTime) > 86400) { |
||
| 127 | $f = 'Y-m-d H:i:s'; |
||
| 128 | } else { |
||
| 129 | $f = 'H:i:s'; |
||
| 130 | } |
||
| 131 | $lastrun = date($f, $lastExecTime); |
||
| 132 | if (!$count) { |
||
| 133 | $lastrun = '- (' . $lastrun . ')'; |
||
| 134 | } |
||
| 135 | } |
||
| 136 | |||
| 137 | $trigger = $task->getNextTriggerTime(); |
||
| 138 | if ($trigger === null) { |
||
| 139 | $nextrun = '-'; |
||
| 140 | } else { |
||
| 141 | if (abs($trigger - time()) > 86400) { |
||
| 142 | $f = 'Y-m-d H:i:s'; |
||
| 143 | } else { |
||
| 144 | $f = 'H:i:s'; |
||
| 145 | } |
||
| 146 | $nextrun = date($f, $trigger) . ($task->getIsPending() ? '*' : ''); |
||
| 147 | } |
||
| 148 | |||
| 149 | if (($user = $task->getUserName()) == null) { |
||
| 150 | $user = $module->getDefaultUserName(); |
||
| 151 | } |
||
| 152 | |||
| 153 | if ($task->getIsPending()) { |
||
| 154 | $nextrun = $this->_outWriter->format($nextrun, [TShellWriter::GREEN, TShellWriter::BOLD]); |
||
| 155 | } |
||
| 156 | |||
| 157 | $rows[] = [$task->getName(), $task->getSchedule(), $task->getTask(), $lastrun, $nextrun, '@' . $user, $count]; |
||
| 158 | } |
||
| 159 | $this->_outWriter->write($this->_outWriter->tableWidget(['headers' => ['Name', 'Schedule', 'Task', 'Last Run', 'Next Run', 'User', 'Run #'], |
||
| 160 | 'rows' => $rows])); |
||
| 161 | $this->_outWriter->writeLine("\nAny 'next run' with a * means it is Pending\n"); |
||
| 162 | |||
| 163 | return true; |
||
| 164 | } |
||
| 196 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.