Conditions | 15 |
Paths | 128 |
Total Lines | 74 |
Code Lines | 50 |
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 |
||
72 | private function generateToc() |
||
73 | { |
||
74 | $ulNode = $this->domDocument->getElementById('toc__ul'); |
||
75 | |||
76 | $folderName = 'document'; |
||
77 | $pathToRemove = ''; |
||
78 | $pathToReplace = ''; |
||
79 | $result = $this->lp->generate_lp_folder($this->courseInfo); |
||
80 | |||
81 | if (isset($result['dir']) && strpos($result['dir'], 'learning_path')) { |
||
82 | $pathToRemove = 'document'.$result['dir']; |
||
83 | $pathToReplace = $folderName; |
||
84 | } |
||
85 | |||
86 | if ($this->lp->ref === 'chamilo_scorm_export') { |
||
87 | $pathToRemove = 'scorm/'.$this->lp->path.'/document/'; |
||
88 | } |
||
89 | |||
90 | foreach ($this->lp->ordered_items as $itemId) { |
||
91 | $item = $this->lp->items[$itemId]; |
||
92 | |||
93 | if (!in_array($item->type, [TOOL_QUIZ, TOOL_FORUM, TOOL_THREAD, TOOL_LINK, TOOL_STUDENTPUBLICATION])) { |
||
94 | $myFilePath = $item->get_file_path('scorm/'.$this->lp->path.'/'); |
||
95 | $itemFilePath = $myFilePath; |
||
96 | |||
97 | if (!empty($pathToRemove)) { |
||
98 | $itemFilePath = str_replace($pathToRemove, $pathToReplace, $myFilePath); |
||
99 | |||
100 | if ($this->lp->ref === 'chamilo_scorm_export') { |
||
101 | $pathToRemove = 'scorm/'.$this->lp->path.'/'; |
||
102 | $itemFilePath = str_replace($pathToRemove, '', $myFilePath); |
||
103 | } |
||
104 | } |
||
105 | } elseif (TOOL_LINK === $item->type) { |
||
106 | $itemFilePath = "link_{$item->get_id()}.html"; |
||
107 | } elseif (TOOL_QUIZ === $item->type) { |
||
108 | $itemFilePath = "quiz_{$item->get_id()}.html"; |
||
109 | } else { |
||
110 | continue; |
||
111 | } |
||
112 | |||
113 | $itemText = htmlspecialchars(api_utf8_encode($item->get_title()), ENT_QUOTES); |
||
114 | |||
115 | $liNode = $this->domDocument->createElement('li'); |
||
116 | $liNode->setAttribute('id', "item_{$item->get_id()}"); |
||
117 | |||
118 | if (!empty($item->parent) && $item->parent != 0) { |
||
119 | $possibleItemParent = $this->lp->get_scorm_xml_node( |
||
120 | $ulNode->childNodes, |
||
121 | "item_$item->parent", |
||
122 | 'li', |
||
123 | 'id' |
||
124 | ); |
||
125 | |||
126 | if ($possibleItemParent instanceof DOMElement) { |
||
127 | $innerUlNode = $possibleItemParent->getElementsByTagName('ul')->item(0) |
||
128 | ?: $this->domDocument->createElement('ul'); |
||
129 | $innerUlNode->appendChild($liNode); |
||
130 | |||
131 | $possibleItemParent->appendChild($innerUlNode); |
||
132 | } |
||
133 | } else { |
||
134 | $ulNode->appendChild($liNode); |
||
135 | } |
||
136 | |||
137 | if (!empty($itemFilePath)) { |
||
138 | $aNode = $this->domDocument->createElement('a', $itemText); |
||
139 | $aNode->setAttribute('href', $itemFilePath); |
||
140 | $aNode->setAttribute('target', 'content-frame'); |
||
141 | |||
142 | $liNode->appendChild($aNode); |
||
143 | } else { |
||
144 | $liNode->appendChild( |
||
145 | $this->domDocument->createTextNode($itemText) |
||
146 | ); |
||
160 |