| Conditions | 7 |
| Paths | 17 |
| Total Lines | 82 |
| Lines | 16 |
| Ratio | 19.51 % |
| 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 |
||
| 63 | public function index() |
||
| 64 | { |
||
| 65 | $tasks = $this->getTasks(); |
||
| 66 | |||
| 67 | $blacklist = (array) $this->config()->get('task_blacklist'); |
||
| 68 | $queuedOnlyList = (array) $this->config()->get('queued_only_tasks'); |
||
| 69 | $backlistedTasks = []; |
||
| 70 | $queuedOnlyTasks = []; |
||
| 71 | |||
| 72 | // Web mode |
||
| 73 | if (!Director::is_cli()) { |
||
| 74 | $renderer = new DebugView(); |
||
| 75 | echo $renderer->renderHeader(); |
||
| 76 | echo $renderer->renderInfo( |
||
| 77 | "SilverStripe Development Tools: Tasks (QueuedJobs version)", |
||
| 78 | Director::absoluteBaseURL() |
||
| 79 | ); |
||
| 80 | $base = Director::absoluteBaseURL(); |
||
| 81 | |||
| 82 | echo "<div class=\"options\">"; |
||
| 83 | echo "<h2>Queueable jobs</h2>\n"; |
||
| 84 | echo "<p>By default these jobs will be added the job queue, rather than run immediately</p>\n"; |
||
| 85 | echo "<ul>"; |
||
| 86 | foreach ($tasks as $task) { |
||
| 87 | if (in_array($task['class'], $blacklist)) { |
||
| 88 | $backlistedTasks[] = $task; |
||
| 89 | |||
| 90 | continue; |
||
| 91 | } |
||
| 92 | |||
| 93 | if (in_array($task['class'], $queuedOnlyList)) { |
||
| 94 | $queuedOnlyTasks[] = $task; |
||
| 95 | |||
| 96 | continue; |
||
| 97 | } |
||
| 98 | |||
| 99 | $queueLink = $base . "dev/tasks/queue/" . $task['segment']; |
||
| 100 | $immediateLink = $base . "dev/tasks/" . $task['segment']; |
||
| 101 | |||
| 102 | echo "<li><p>"; |
||
| 103 | echo "<a href=\"$queueLink\">" . $task['title'] . "</a> <a style=\"font-size: 80%; padding-left: 20px\"" |
||
| 104 | . " href=\"$immediateLink\">[run immediately]</a><br />"; |
||
| 105 | echo "<span class=\"description\">" . $task['description'] . "</span>"; |
||
| 106 | echo "</p></li>\n"; |
||
| 107 | } |
||
| 108 | echo "</ul></div>"; |
||
| 109 | |||
| 110 | echo "<div class=\"options\">"; |
||
| 111 | echo "<h2>Non-queueable tasks</h2>\n"; |
||
| 112 | echo "<p>These tasks shouldn't be added the queuejobs queue, but you can run them immediately.</p>\n"; |
||
| 113 | echo "<ul>"; |
||
| 114 | View Code Duplication | foreach ($backlistedTasks as $task) { |
|
| 115 | $immediateLink = $base . "dev/tasks/" . $task['segment']; |
||
| 116 | |||
| 117 | echo "<li><p>"; |
||
| 118 | echo "<a href=\"$immediateLink\">" . $task['title'] . "</a><br />"; |
||
| 119 | echo "<span class=\"description\">" . $task['description'] . "</span>"; |
||
| 120 | echo "</p></li>\n"; |
||
| 121 | } |
||
| 122 | echo "</ul></div>"; |
||
| 123 | |||
| 124 | echo "<div class=\"options\">"; |
||
| 125 | echo "<h2>Queueable only tasks</h2>\n"; |
||
| 126 | echo "<p>These tasks must be be added the queuejobs queue, running it immediately is not allowed.</p>\n"; |
||
| 127 | echo "<ul>"; |
||
| 128 | View Code Duplication | foreach ($queuedOnlyTasks as $task) { |
|
| 129 | $queueLink = $base . "dev/tasks/queue/" . $task['segment']; |
||
| 130 | |||
| 131 | echo "<li><p>"; |
||
| 132 | echo "<a href=\"$queueLink\">" . $task['title'] . "</a><br />"; |
||
| 133 | echo "<span class=\"description\">" . $task['description'] . "</span>"; |
||
| 134 | echo "</p></li>\n"; |
||
| 135 | } |
||
| 136 | echo "</ul></div>"; |
||
| 137 | |||
| 138 | echo $renderer->renderFooter(); |
||
| 139 | |||
| 140 | // CLI mode - revert to default behaviour |
||
| 141 | } else { |
||
| 142 | return parent::index(); |
||
| 143 | } |
||
| 144 | } |
||
| 145 | |||
| 197 |