| Conditions | 6 |
| Paths | 6 |
| Total Lines | 79 |
| Code Lines | 67 |
| 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 |
||
| 156 | private function createGlossaryXml(array $glossaryData, string $glossaryDir): void |
||
| 157 | { |
||
| 158 | $esc = static function (?string $html): string { |
||
| 159 | return htmlspecialchars((string) $html, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); |
||
| 160 | }; |
||
| 161 | |||
| 162 | $introHtml = $glossaryData['description'] !== '' |
||
| 163 | ? $glossaryData['description'] |
||
| 164 | : '<p>'.get_lang('Glossary').'</p>'; |
||
| 165 | |||
| 166 | $xml = '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL; |
||
| 167 | $xml .= '<activity id="'.$glossaryData['id'].'" moduleid="'.$glossaryData['moduleid'].'" modulename="'.$glossaryData['modulename'].'" contextid="'.$glossaryData['contextid'].'">'.PHP_EOL; |
||
| 168 | $xml .= ' <glossary id="'.$glossaryData['id'].'">'.PHP_EOL; |
||
| 169 | $xml .= ' <name>'.$esc((string) $glossaryData['name']).'</name>'.PHP_EOL; |
||
| 170 | $xml .= ' <intro>'.$esc($introHtml).'</intro>'.PHP_EOL; |
||
| 171 | $xml .= ' <introformat>1</introformat>'.PHP_EOL; |
||
| 172 | $xml .= ' <allowduplicatedentries>0</allowduplicatedentries>'.PHP_EOL; |
||
| 173 | $xml .= ' <displayformat>dictionary</displayformat>'.PHP_EOL; |
||
| 174 | $xml .= ' <mainglossary>0</mainglossary>'.PHP_EOL; |
||
| 175 | $xml .= ' <showspecial>1</showspecial>'.PHP_EOL; |
||
| 176 | $xml .= ' <showalphabet>1</showalphabet>'.PHP_EOL; |
||
| 177 | $xml .= ' <showall>1</showall>'.PHP_EOL; |
||
| 178 | $xml .= ' <allowcomments>0</allowcomments>'.PHP_EOL; |
||
| 179 | $xml .= ' <allowprintview>1</allowprintview>'.PHP_EOL; |
||
| 180 | $xml .= ' <usedynalink>1</usedynalink>'.PHP_EOL; |
||
| 181 | $xml .= ' <defaultapproval>1</defaultapproval>'.PHP_EOL; |
||
| 182 | $xml .= ' <globalglossary>0</globalglossary>'.PHP_EOL; |
||
| 183 | $xml .= ' <entbypage>10</entbypage>'.PHP_EOL; |
||
| 184 | $xml .= ' <editalways>0</editalways>'.PHP_EOL; |
||
| 185 | $xml .= ' <rsstype>0</rsstype>'.PHP_EOL; |
||
| 186 | $xml .= ' <rssarticles>0</rssarticles>'.PHP_EOL; |
||
| 187 | $xml .= ' <assessed>0</assessed>'.PHP_EOL; |
||
| 188 | $xml .= ' <assesstimestart>0</assesstimestart>'.PHP_EOL; |
||
| 189 | $xml .= ' <assesstimefinish>0</assesstimefinish>'.PHP_EOL; |
||
| 190 | $xml .= ' <scale>100</scale>'.PHP_EOL; |
||
| 191 | $xml .= ' <timecreated>'.$glossaryData['timecreated'].'</timecreated>'.PHP_EOL; |
||
| 192 | $xml .= ' <timemodified>'.$glossaryData['timemodified'].'</timemodified>'.PHP_EOL; |
||
| 193 | $xml .= ' <completionentries>0</completionentries>'.PHP_EOL; |
||
| 194 | |||
| 195 | // Entries |
||
| 196 | $xml .= ' <entries>'.PHP_EOL; |
||
| 197 | foreach ($glossaryData['entries'] as $entry) { |
||
| 198 | $xml .= ' <entry id="'.$entry['id'].'">'.PHP_EOL; |
||
| 199 | $xml .= ' <userid>'.$entry['userid'].'</userid>'.PHP_EOL; |
||
| 200 | $xml .= ' <concept>'.$esc((string) $entry['concept']).'</concept>'.PHP_EOL; |
||
| 201 | $xml .= ' <definition>'.$esc((string) $entry['definition']).'</definition>'.PHP_EOL; |
||
| 202 | $xml .= ' <definitionformat>1</definitionformat>'.PHP_EOL; |
||
| 203 | $xml .= ' <definitiontrust>0</definitiontrust>'.PHP_EOL; |
||
| 204 | $xml .= ' <attachment></attachment>'.PHP_EOL; |
||
| 205 | $xml .= ' <timecreated>'.$entry['timecreated'].'</timecreated>'.PHP_EOL; |
||
| 206 | $xml .= ' <timemodified>'.$entry['timemodified'].'</timemodified>'.PHP_EOL; |
||
| 207 | $xml .= ' <teacherentry>1</teacherentry>'.PHP_EOL; |
||
| 208 | $xml .= ' <sourceglossaryid>0</sourceglossaryid>'.PHP_EOL; |
||
| 209 | $xml .= ' <usedynalink>1</usedynalink>'.PHP_EOL; |
||
| 210 | $xml .= ' <casesensitive>0</casesensitive>'.PHP_EOL; |
||
| 211 | $xml .= ' <fullmatch>0</fullmatch>'.PHP_EOL; |
||
| 212 | $xml .= ' <approved>1</approved>'.PHP_EOL; |
||
| 213 | $xml .= ' <aliases>'.PHP_EOL; |
||
| 214 | $aliasId = 1; |
||
| 215 | if (!empty($entry['aliases']) && \is_array($entry['aliases'])) { |
||
| 216 | foreach ($entry['aliases'] as $a) { |
||
| 217 | $xml .= ' <alias id="'.$aliasId.'">'.PHP_EOL; |
||
| 218 | $xml .= ' <alias_text>'.$esc((string) $a).'</alias_text>'.PHP_EOL; |
||
| 219 | $xml .= ' </alias>'.PHP_EOL; |
||
| 220 | $aliasId++; |
||
| 221 | } |
||
| 222 | } |
||
| 223 | $xml .= ' </aliases>'.PHP_EOL; |
||
| 224 | $xml .= ' <ratings></ratings>'.PHP_EOL; |
||
| 225 | $xml .= ' </entry>'.PHP_EOL; |
||
| 226 | } |
||
| 227 | $xml .= ' </entries>'.PHP_EOL; |
||
| 228 | |||
| 229 | $xml .= ' <entriestags></entriestags>'.PHP_EOL; |
||
| 230 | $xml .= ' <categories></categories>'.PHP_EOL; |
||
| 231 | $xml .= ' </glossary>'.PHP_EOL; |
||
| 232 | $xml .= '</activity>'; |
||
| 233 | |||
| 234 | $this->createXmlFile('glossary', $xml, $glossaryDir); |
||
| 235 | } |
||
| 237 |