| Conditions | 3 |
| Paths | 3 |
| Total Lines | 85 |
| Code Lines | 74 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 132 | private function createForumXml(array $data, string $forumDir): void |
||
| 133 | { |
||
| 134 | $introCdata = '<![CDATA['.(string) $data['description'].']]>'; |
||
| 135 | |||
| 136 | $xml = '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL; |
||
| 137 | $xml .= '<activity id="'.$data['id'].'" moduleid="'.$data['moduleid'].'" modulename="forum" contextid="'.$data['contextid'].'">'.PHP_EOL; |
||
| 138 | $xml .= ' <forum id="'.$data['id'].'">'.PHP_EOL; |
||
| 139 | $xml .= ' <type>'.htmlspecialchars((string) ($data['type'] ?? 'news')).'</type>'.PHP_EOL; |
||
| 140 | $xml .= ' <name>'.htmlspecialchars((string) $data['name']).'</name>'.PHP_EOL; |
||
| 141 | $xml .= ' <intro>'.$introCdata.'</intro>'.PHP_EOL; |
||
| 142 | $xml .= ' <introformat>1</introformat>'.PHP_EOL; |
||
| 143 | $xml .= ' <duedate>0</duedate>'.PHP_EOL; |
||
| 144 | $xml .= ' <cutoffdate>0</cutoffdate>'.PHP_EOL; |
||
| 145 | $xml .= ' <assessed>0</assessed>'.PHP_EOL; |
||
| 146 | $xml .= ' <assesstimestart>0</assesstimestart>'.PHP_EOL; |
||
| 147 | $xml .= ' <assesstimefinish>0</assesstimefinish>'.PHP_EOL; |
||
| 148 | $xml .= ' <scale>100</scale>'.PHP_EOL; |
||
| 149 | $xml .= ' <maxbytes>512000</maxbytes>'.PHP_EOL; |
||
| 150 | $xml .= ' <maxattachments>9</maxattachments>'.PHP_EOL; |
||
| 151 | $xml .= ' <forcesubscribe>'.(int) ($data['forcesubscribe'] ?? 1).'</forcesubscribe>'.PHP_EOL; |
||
| 152 | $xml .= ' <trackingtype>1</trackingtype>'.PHP_EOL; |
||
| 153 | $xml .= ' <rsstype>0</rsstype>'.PHP_EOL; |
||
| 154 | $xml .= ' <rssarticles>0</rssarticles>'.PHP_EOL; |
||
| 155 | $xml .= ' <timemodified>'.$data['timemodified'].'</timemodified>'.PHP_EOL; |
||
| 156 | $xml .= ' <warnafter>0</warnafter>'.PHP_EOL; |
||
| 157 | $xml .= ' <blockafter>0</blockafter>'.PHP_EOL; |
||
| 158 | $xml .= ' <blockperiod>0</blockperiod>'.PHP_EOL; |
||
| 159 | $xml .= ' <completiondiscussions>0</completiondiscussions>'.PHP_EOL; |
||
| 160 | $xml .= ' <completionreplies>0</completionreplies>'.PHP_EOL; |
||
| 161 | $xml .= ' <completionposts>0</completionposts>'.PHP_EOL; |
||
| 162 | $xml .= ' <displaywordcount>0</displaywordcount>'.PHP_EOL; |
||
| 163 | $xml .= ' <lockdiscussionafter>0</lockdiscussionafter>'.PHP_EOL; |
||
| 164 | $xml .= ' <grade_forum>0</grade_forum>'.PHP_EOL; |
||
| 165 | |||
| 166 | $xml .= ' <discussions>'.PHP_EOL; |
||
| 167 | foreach ($data['threads'] as $thread) { |
||
| 168 | $xml .= ' <discussion id="'.$thread['id'].'">'.PHP_EOL; |
||
| 169 | $xml .= ' <name>'.htmlspecialchars((string) $thread['title']).'</name>'.PHP_EOL; |
||
| 170 | $xml .= ' <firstpost>'.(int) $thread['firstpost'].'</firstpost>'.PHP_EOL; |
||
| 171 | $xml .= ' <userid>'.$thread['userid'].'</userid>'.PHP_EOL; |
||
| 172 | $xml .= ' <groupid>-1</groupid>'.PHP_EOL; |
||
| 173 | $xml .= ' <assessed>0</assessed>'.PHP_EOL; |
||
| 174 | $xml .= ' <timemodified>'.$thread['timemodified'].'</timemodified>'.PHP_EOL; |
||
| 175 | $xml .= ' <usermodified>'.$thread['usermodified'].'</usermodified>'.PHP_EOL; |
||
| 176 | $xml .= ' <timestart>0</timestart>'.PHP_EOL; |
||
| 177 | $xml .= ' <timeend>0</timeend>'.PHP_EOL; |
||
| 178 | $xml .= ' <pinned>0</pinned>'.PHP_EOL; |
||
| 179 | $xml .= ' <timelocked>0</timelocked>'.PHP_EOL; |
||
| 180 | |||
| 181 | $xml .= ' <posts>'.PHP_EOL; |
||
| 182 | foreach ($thread['posts'] as $post) { |
||
| 183 | $xml .= ' <post id="'.$post['id'].'">'.PHP_EOL; |
||
| 184 | $xml .= ' <parent>'.(int) $post['parent'].'</parent>'.PHP_EOL; |
||
| 185 | $xml .= ' <userid>'.$post['userid'].'</userid>'.PHP_EOL; |
||
| 186 | $xml .= ' <created>'.$post['created'].'</created>'.PHP_EOL; |
||
| 187 | $xml .= ' <modified>'.$post['modified'].'</modified>'.PHP_EOL; |
||
| 188 | $xml .= ' <mailed>'.(int) $post['mailed'].'</mailed>'.PHP_EOL; |
||
| 189 | $xml .= ' <subject>'.htmlspecialchars((string) $post['subject']).'</subject>'.PHP_EOL; |
||
| 190 | $xml .= ' <message><![CDATA['.$post['message'].']]></message>'.PHP_EOL; |
||
| 191 | $xml .= ' <messageformat>1</messageformat>'.PHP_EOL; |
||
| 192 | $xml .= ' <messagetrust>0</messagetrust>'.PHP_EOL; |
||
| 193 | $xml .= ' <attachment></attachment>'.PHP_EOL; |
||
| 194 | $xml .= ' <totalscore>0</totalscore>'.PHP_EOL; |
||
| 195 | $xml .= ' <mailnow>0</mailnow>'.PHP_EOL; |
||
| 196 | $xml .= ' <privatereplyto>0</privatereplyto>'.PHP_EOL; |
||
| 197 | $xml .= ' <ratings></ratings>'.PHP_EOL; |
||
| 198 | $xml .= ' </post>'.PHP_EOL; |
||
| 199 | } |
||
| 200 | $xml .= ' </posts>'.PHP_EOL; |
||
| 201 | |||
| 202 | $xml .= ' <discussion_subs>'.PHP_EOL; |
||
| 203 | $xml .= ' <discussion_sub id="'.$thread['id'].'">'.PHP_EOL; |
||
| 204 | $xml .= ' <userid>'.$thread['userid'].'</userid>'.PHP_EOL; |
||
| 205 | $xml .= ' <preference>'.$thread['timemodified'].'</preference>'.PHP_EOL; |
||
| 206 | $xml .= ' </discussion_sub>'.PHP_EOL; |
||
| 207 | $xml .= ' </discussion_subs>'.PHP_EOL; |
||
| 208 | |||
| 209 | $xml .= ' </discussion>'.PHP_EOL; |
||
| 210 | } |
||
| 211 | $xml .= ' </discussions>'.PHP_EOL; |
||
| 212 | |||
| 213 | $xml .= ' </forum>'.PHP_EOL; |
||
| 214 | $xml .= '</activity>'; |
||
| 215 | |||
| 216 | $this->createXmlFile('forum', $xml, $forumDir); |
||
| 217 | } |
||
| 289 |