| 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 |
||
| 107 | private function createForumXml(array $forumData, string $forumDir): void |
||
| 108 | { |
||
| 109 | $xmlContent = '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL; |
||
| 110 | $xmlContent .= '<activity id="'.$forumData['id'].'" moduleid="'.$forumData['moduleid'].'" modulename="'.$forumData['modulename'].'" contextid="'.$forumData['contextid'].'">'.PHP_EOL; |
||
| 111 | $xmlContent .= ' <forum id="'.$forumData['id'].'">'.PHP_EOL; |
||
| 112 | $xmlContent .= ' <type>general</type>'.PHP_EOL; |
||
| 113 | $xmlContent .= ' <name>'.htmlspecialchars($forumData['name']).'</name>'.PHP_EOL; |
||
| 114 | $xmlContent .= ' <intro>'.htmlspecialchars($forumData['description']).'</intro>'.PHP_EOL; |
||
| 115 | $xmlContent .= ' <introformat>1</introformat>'.PHP_EOL; |
||
| 116 | $xmlContent .= ' <duedate>0</duedate>'.PHP_EOL; |
||
| 117 | $xmlContent .= ' <cutoffdate>0</cutoffdate>'.PHP_EOL; |
||
| 118 | $xmlContent .= ' <assessed>0</assessed>'.PHP_EOL; |
||
| 119 | $xmlContent .= ' <assesstimestart>0</assesstimestart>'.PHP_EOL; |
||
| 120 | $xmlContent .= ' <assesstimefinish>0</assesstimefinish>'.PHP_EOL; |
||
| 121 | $xmlContent .= ' <scale>100</scale>'.PHP_EOL; |
||
| 122 | $xmlContent .= ' <maxbytes>512000</maxbytes>'.PHP_EOL; |
||
| 123 | $xmlContent .= ' <maxattachments>9</maxattachments>'.PHP_EOL; |
||
| 124 | $xmlContent .= ' <forcesubscribe>0</forcesubscribe>'.PHP_EOL; |
||
| 125 | $xmlContent .= ' <trackingtype>1</trackingtype>'.PHP_EOL; |
||
| 126 | $xmlContent .= ' <rsstype>0</rsstype>'.PHP_EOL; |
||
| 127 | $xmlContent .= ' <rssarticles>0</rssarticles>'.PHP_EOL; |
||
| 128 | $xmlContent .= ' <timemodified>'.$forumData['timemodified'].'</timemodified>'.PHP_EOL; |
||
| 129 | $xmlContent .= ' <warnafter>0</warnafter>'.PHP_EOL; |
||
| 130 | $xmlContent .= ' <blockafter>0</blockafter>'.PHP_EOL; |
||
| 131 | $xmlContent .= ' <blockperiod>0</blockperiod>'.PHP_EOL; |
||
| 132 | $xmlContent .= ' <completiondiscussions>0</completiondiscussions>'.PHP_EOL; |
||
| 133 | $xmlContent .= ' <completionreplies>0</completionreplies>'.PHP_EOL; |
||
| 134 | $xmlContent .= ' <completionposts>0</completionposts>'.PHP_EOL; |
||
| 135 | $xmlContent .= ' <displaywordcount>0</displaywordcount>'.PHP_EOL; |
||
| 136 | $xmlContent .= ' <lockdiscussionafter>0</lockdiscussionafter>'.PHP_EOL; |
||
| 137 | $xmlContent .= ' <grade_forum>0</grade_forum>'.PHP_EOL; |
||
| 138 | |||
| 139 | // Add forum threads |
||
| 140 | $xmlContent .= ' <discussions>'.PHP_EOL; |
||
| 141 | foreach ($forumData['threads'] as $thread) { |
||
| 142 | $xmlContent .= ' <discussion id="'.$thread['id'].'">'.PHP_EOL; |
||
| 143 | $xmlContent .= ' <name>'.htmlspecialchars($thread['title']).'</name>'.PHP_EOL; |
||
| 144 | $xmlContent .= ' <firstpost>'.$thread['firstpost'].'</firstpost>'.PHP_EOL; |
||
| 145 | $xmlContent .= ' <userid>'.$thread['userid'].'</userid>'.PHP_EOL; |
||
| 146 | $xmlContent .= ' <groupid>-1</groupid>'.PHP_EOL; |
||
| 147 | $xmlContent .= ' <assessed>0</assessed>'.PHP_EOL; |
||
| 148 | $xmlContent .= ' <timemodified>'.$thread['timemodified'].'</timemodified>'.PHP_EOL; |
||
| 149 | $xmlContent .= ' <usermodified>'.$thread['usermodified'].'</usermodified>'.PHP_EOL; |
||
| 150 | $xmlContent .= ' <timestart>0</timestart>'.PHP_EOL; |
||
| 151 | $xmlContent .= ' <timeend>0</timeend>'.PHP_EOL; |
||
| 152 | $xmlContent .= ' <pinned>0</pinned>'.PHP_EOL; |
||
| 153 | $xmlContent .= ' <timelocked>0</timelocked>'.PHP_EOL; |
||
| 154 | |||
| 155 | // Add forum posts to the thread |
||
| 156 | $xmlContent .= ' <posts>'.PHP_EOL; |
||
| 157 | foreach ($thread['posts'] as $post) { |
||
| 158 | $xmlContent .= ' <post id="'.$post['id'].'">'.PHP_EOL; |
||
| 159 | $xmlContent .= ' <parent>'.$post['parent'].'</parent>'.PHP_EOL; |
||
| 160 | $xmlContent .= ' <userid>'.$post['userid'].'</userid>'.PHP_EOL; |
||
| 161 | $xmlContent .= ' <created>'.$post['created'].'</created>'.PHP_EOL; |
||
| 162 | $xmlContent .= ' <modified>'.$post['modified'].'</modified>'.PHP_EOL; |
||
| 163 | $xmlContent .= ' <mailed>'.$post['mailed'].'</mailed>'.PHP_EOL; |
||
| 164 | $xmlContent .= ' <subject>'.htmlspecialchars($post['subject']).'</subject>'.PHP_EOL; |
||
| 165 | $xmlContent .= ' <message>'.htmlspecialchars($post['message']).'</message>'.PHP_EOL; |
||
| 166 | $xmlContent .= ' <messageformat>1</messageformat>'.PHP_EOL; |
||
| 167 | $xmlContent .= ' <messagetrust>0</messagetrust>'.PHP_EOL; |
||
| 168 | $xmlContent .= ' <attachment></attachment>'.PHP_EOL; |
||
| 169 | $xmlContent .= ' <totalscore>0</totalscore>'.PHP_EOL; |
||
| 170 | $xmlContent .= ' <mailnow>0</mailnow>'.PHP_EOL; |
||
| 171 | $xmlContent .= ' <privatereplyto>0</privatereplyto>'.PHP_EOL; |
||
| 172 | $xmlContent .= ' <ratings>'.PHP_EOL; |
||
| 173 | $xmlContent .= ' </ratings>'.PHP_EOL; |
||
| 174 | $xmlContent .= ' </post>'.PHP_EOL; |
||
| 175 | } |
||
| 176 | $xmlContent .= ' </posts>'.PHP_EOL; |
||
| 177 | $xmlContent .= ' <discussion_subs>'.PHP_EOL; |
||
| 178 | $xmlContent .= ' <discussion_sub id="'.$thread['id'].'">'.PHP_EOL; |
||
| 179 | $xmlContent .= ' <userid>'.$thread['userid'].'</userid>'.PHP_EOL; |
||
| 180 | $xmlContent .= ' <preference>'.$thread['timemodified'].'</preference>'.PHP_EOL; |
||
| 181 | $xmlContent .= ' </discussion_sub>'.PHP_EOL; |
||
| 182 | $xmlContent .= ' </discussion_subs>'.PHP_EOL; |
||
| 183 | $xmlContent .= ' </discussion>'.PHP_EOL; |
||
| 184 | } |
||
| 185 | $xmlContent .= ' </discussions>'.PHP_EOL; |
||
| 186 | $xmlContent .= ' </forum>'.PHP_EOL; |
||
| 187 | $xmlContent .= '</activity>'; |
||
| 188 | |||
| 189 | $this->createXmlFile('forum', $xmlContent, $forumDir); |
||
| 190 | } |
||
| 192 |