| Conditions | 3 |
| Paths | 3 |
| Total Lines | 83 |
| Code Lines | 74 |
| 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 |
||
| 46 | private function createForumXml(array $forumData, string $forumDir): void |
||
| 47 | { |
||
| 48 | $xmlContent = '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL; |
||
| 49 | $xmlContent .= '<activity id="' . $forumData['id'] . '" moduleid="' . $forumData['moduleid'] . '" modulename="'.$forumData['modulename'].'" contextid="' . $forumData['contextid'] . '">' . PHP_EOL; |
||
| 50 | $xmlContent .= ' <forum id="' . $forumData['id'] . '">' . PHP_EOL; |
||
| 51 | $xmlContent .= ' <type>general</type>' . PHP_EOL; |
||
| 52 | $xmlContent .= ' <name>' . htmlspecialchars($forumData['name']) . '</name>' . PHP_EOL; |
||
| 53 | $xmlContent .= ' <intro>' . htmlspecialchars($forumData['description']) . '</intro>' . PHP_EOL; |
||
| 54 | $xmlContent .= ' <introformat>1</introformat>' . PHP_EOL; |
||
| 55 | $xmlContent .= ' <duedate>0</duedate>' . PHP_EOL; |
||
| 56 | $xmlContent .= ' <cutoffdate>0</cutoffdate>' . PHP_EOL; |
||
| 57 | $xmlContent .= ' <assessed>0</assessed>' . PHP_EOL; |
||
| 58 | $xmlContent .= ' <assesstimestart>0</assesstimestart>' . PHP_EOL; |
||
| 59 | $xmlContent .= ' <assesstimefinish>0</assesstimefinish>' . PHP_EOL; |
||
| 60 | $xmlContent .= ' <scale>100</scale>' . PHP_EOL; |
||
| 61 | $xmlContent .= ' <maxbytes>512000</maxbytes>' . PHP_EOL; |
||
| 62 | $xmlContent .= ' <maxattachments>9</maxattachments>' . PHP_EOL; |
||
| 63 | $xmlContent .= ' <forcesubscribe>0</forcesubscribe>' . PHP_EOL; |
||
| 64 | $xmlContent .= ' <trackingtype>1</trackingtype>' . PHP_EOL; |
||
| 65 | $xmlContent .= ' <rsstype>0</rsstype>' . PHP_EOL; |
||
| 66 | $xmlContent .= ' <rssarticles>0</rssarticles>' . PHP_EOL; |
||
| 67 | $xmlContent .= ' <timemodified>' . $forumData['timemodified'] . '</timemodified>' . PHP_EOL; |
||
| 68 | $xmlContent .= ' <warnafter>0</warnafter>' . PHP_EOL; |
||
| 69 | $xmlContent .= ' <blockafter>0</blockafter>' . PHP_EOL; |
||
| 70 | $xmlContent .= ' <blockperiod>0</blockperiod>' . PHP_EOL; |
||
| 71 | $xmlContent .= ' <completiondiscussions>0</completiondiscussions>' . PHP_EOL; |
||
| 72 | $xmlContent .= ' <completionreplies>0</completionreplies>' . PHP_EOL; |
||
| 73 | $xmlContent .= ' <completionposts>0</completionposts>' . PHP_EOL; |
||
| 74 | $xmlContent .= ' <displaywordcount>0</displaywordcount>' . PHP_EOL; |
||
| 75 | $xmlContent .= ' <lockdiscussionafter>0</lockdiscussionafter>' . PHP_EOL; |
||
| 76 | $xmlContent .= ' <grade_forum>0</grade_forum>' . PHP_EOL; |
||
| 77 | |||
| 78 | // Add forum threads |
||
| 79 | $xmlContent .= ' <discussions>' . PHP_EOL; |
||
| 80 | foreach ($forumData['threads'] as $thread) { |
||
| 81 | $xmlContent .= ' <discussion id="' . $thread['id'] . '">' . PHP_EOL; |
||
| 82 | $xmlContent .= ' <name>' . htmlspecialchars($thread['title']) . '</name>' . PHP_EOL; |
||
| 83 | $xmlContent .= ' <firstpost>' . $thread['firstpost'] . '</firstpost>' . PHP_EOL; |
||
| 84 | $xmlContent .= ' <userid>' . $thread['userid'] . '</userid>' . PHP_EOL; |
||
| 85 | $xmlContent .= ' <groupid>-1</groupid>' . PHP_EOL; |
||
| 86 | $xmlContent .= ' <assessed>0</assessed>' . PHP_EOL; |
||
| 87 | $xmlContent .= ' <timemodified>' . $thread['timemodified'] . '</timemodified>' . PHP_EOL; |
||
| 88 | $xmlContent .= ' <usermodified>' . $thread['usermodified'] . '</usermodified>' . PHP_EOL; |
||
| 89 | $xmlContent .= ' <timestart>0</timestart>' . PHP_EOL; |
||
| 90 | $xmlContent .= ' <timeend>0</timeend>' . PHP_EOL; |
||
| 91 | $xmlContent .= ' <pinned>0</pinned>' . PHP_EOL; |
||
| 92 | $xmlContent .= ' <timelocked>0</timelocked>' . PHP_EOL; |
||
| 93 | |||
| 94 | // Add forum posts to the thread |
||
| 95 | $xmlContent .= ' <posts>' . PHP_EOL; |
||
| 96 | foreach ($thread['posts'] as $post) { |
||
| 97 | $xmlContent .= ' <post id="' . $post['id'] . '">' . PHP_EOL; |
||
| 98 | $xmlContent .= ' <parent>' . $post['parent'] . '</parent>' . PHP_EOL; |
||
| 99 | $xmlContent .= ' <userid>' . $post['userid'] . '</userid>' . PHP_EOL; |
||
| 100 | $xmlContent .= ' <created>' . $post['created'] . '</created>' . PHP_EOL; |
||
| 101 | $xmlContent .= ' <modified>' . $post['modified'] . '</modified>' . PHP_EOL; |
||
| 102 | $xmlContent .= ' <mailed>' . $post['mailed'] . '</mailed>' . PHP_EOL; |
||
| 103 | $xmlContent .= ' <subject>' . htmlspecialchars($post['subject']) . '</subject>' . PHP_EOL; |
||
| 104 | $xmlContent .= ' <message>' . htmlspecialchars($post['message']) . '</message>' . PHP_EOL; |
||
| 105 | $xmlContent .= ' <messageformat>1</messageformat>' . PHP_EOL; |
||
| 106 | $xmlContent .= ' <messagetrust>0</messagetrust>' . PHP_EOL; |
||
| 107 | $xmlContent .= ' <attachment></attachment>' . PHP_EOL; |
||
| 108 | $xmlContent .= ' <totalscore>0</totalscore>' . PHP_EOL; |
||
| 109 | $xmlContent .= ' <mailnow>0</mailnow>' . PHP_EOL; |
||
| 110 | $xmlContent .= ' <privatereplyto>0</privatereplyto>' . PHP_EOL; |
||
| 111 | $xmlContent .= ' <ratings>' . PHP_EOL; |
||
| 112 | $xmlContent .= ' </ratings>' . PHP_EOL; |
||
| 113 | $xmlContent .= ' </post>' . PHP_EOL; |
||
| 114 | } |
||
| 115 | $xmlContent .= ' </posts>' . PHP_EOL; |
||
| 116 | $xmlContent .= ' <discussion_subs>' . PHP_EOL; |
||
| 117 | $xmlContent .= ' <discussion_sub id="'.$thread['id'].'">' . PHP_EOL; |
||
| 118 | $xmlContent .= ' <userid>' . $thread['userid'] . '</userid>' . PHP_EOL; |
||
| 119 | $xmlContent .= ' <preference>' . $thread['timemodified'] . '</preference>' . PHP_EOL; |
||
| 120 | $xmlContent .= ' </discussion_sub>' . PHP_EOL; |
||
| 121 | $xmlContent .= ' </discussion_subs>' . PHP_EOL; |
||
| 122 | $xmlContent .= ' </discussion>' . PHP_EOL; |
||
| 123 | } |
||
| 124 | $xmlContent .= ' </discussions>' . PHP_EOL; |
||
| 125 | $xmlContent .= ' </forum>' . PHP_EOL; |
||
| 126 | $xmlContent .= '</activity>'; |
||
| 127 | |||
| 128 | $this->createXmlFile('forum', $xmlContent, $forumDir); |
||
| 129 | } |
||
| 189 |