Conditions | 5 |
Paths | 7 |
Total Lines | 55 |
Code Lines | 38 |
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 |
||
37 | public function index() |
||
38 | { |
||
39 | $tasks = $this->getTasks(); |
||
40 | |||
41 | $blacklist = (array)$this->config()->task_blacklist; |
||
42 | $backlistedTasks = array(); |
||
43 | |||
44 | // Web mode |
||
45 | if(!Director::is_cli()) { |
||
46 | $renderer = new DebugView(); |
||
47 | echo $renderer->renderHeader(); |
||
48 | echo $renderer->renderInfo("SilverStripe Development Tools: Tasks (QueuedJobs version)", Director::absoluteBaseURL()); |
||
49 | $base = Director::absoluteBaseURL(); |
||
50 | |||
51 | echo "<div class=\"options\">"; |
||
52 | echo "<h2>Queueable jobs</h2>\n"; |
||
53 | echo "<p>By default these jobs will be added the job queue, rather than run immediately</p>\n"; |
||
54 | echo "<ul>"; |
||
55 | foreach ($tasks as $task) { |
||
56 | if (in_array($task['class'], $blacklist)) { |
||
57 | $backlistedTasks[] = $task; |
||
58 | continue; |
||
59 | } |
||
60 | |||
61 | $queueLink = $base . "dev/tasks/queue/" . $task['segment']; |
||
62 | $immediateLink = $base . "dev/tasks/" . $task['segment']; |
||
63 | |||
64 | echo "<li><p>"; |
||
65 | echo "<a href=\"$queueLink\">" . $task['title'] . "</a> <a style=\"font-size: 80%; padding-left: 20px\" href=\"$immediateLink\">[run immediately]</a><br />"; |
||
66 | echo "<span class=\"description\">" . $task['description'] . "</span>"; |
||
67 | echo "</p></li>\n"; |
||
68 | } |
||
69 | echo "</ul></div>"; |
||
70 | |||
71 | echo "<div class=\"options\">"; |
||
72 | echo "<h2>Non-queueable tasks</h2>\n"; |
||
73 | echo "<p>These tasks shouldn't be added the queuejobs queue, but you can run them immediately.</p>\n"; |
||
74 | echo "<ul>"; |
||
75 | foreach ($backlistedTasks as $task) { |
||
76 | $immediateLink = $base . "dev/tasks/" . $task['segment']; |
||
77 | |||
78 | echo "<li><p>"; |
||
79 | echo "<a href=\"$immediateLink\">" . $task['title'] . "</a><br />"; |
||
80 | echo "<span class=\"description\">" . $task['description'] . "</span>"; |
||
81 | echo "</p></li>\n"; |
||
82 | } |
||
83 | echo "</ul></div>"; |
||
84 | |||
85 | echo $renderer->renderFooter(); |
||
86 | |||
87 | // CLI mode - revert to default behaviour |
||
88 | } else { |
||
89 | return parent::index(); |
||
90 | } |
||
91 | } |
||
92 | |||
142 |