| Conditions | 7 |
| Paths | 27 |
| Total Lines | 76 |
| Code Lines | 49 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 87 | public function getFiles() |
||
| 88 | { |
||
| 89 | $xpath = $this->getMetsXpath(); |
||
| 90 | |||
| 91 | $xpath->registerNamespace("xlink", "http://www.w3.org/1999/xlink"); |
||
| 92 | |||
| 93 | $fileNodesOriginal = $xpath->query('/mets:mets/mets:fileSec/mets:fileGrp[@USE="ORIGINAL"]/mets:file'); |
||
| 94 | $fileNodesDownload = $xpath->query('/mets:mets/mets:fileSec/mets:fileGrp[@USE="DOWNLOAD"]/mets:file'); |
||
| 95 | $fileNodesDeleted = $xpath->query('/mets:mets/mets:fileSec/mets:fileGrp[@USE="DELETED"]/mets:file'); |
||
| 96 | |||
| 97 | $files = array(); |
||
| 98 | |||
| 99 | foreach ($fileNodesOriginal as $item) { |
||
| 100 | |||
| 101 | $xlinkNS = "http://www.w3.org/1999/xlink"; |
||
| 102 | $mextNS = "http://slub-dresden.de/mets"; |
||
| 103 | |||
| 104 | $flocat = $xpath->query('mets:FLocat', $item); |
||
| 105 | if ($flocat->length > 0) { |
||
| 106 | $href = $flocat->item(0)->getAttributeNS($xlinkNS, "href"); |
||
| 107 | } |
||
| 108 | |||
| 109 | $files[] = array( |
||
| 110 | 'id' => $item->getAttribute("ID"), |
||
| 111 | 'mimetype' => $item->getAttribute("MIMETYPE"), |
||
| 112 | 'href' => $href, |
||
|
|
|||
| 113 | 'title' => $item->getAttributeNS($mextNS, "LABEL"), |
||
| 114 | 'archive' => ($item->getAttribute("USE") == 'ARCHIVE'), |
||
| 115 | 'download' => false, |
||
| 116 | 'deleted' => false, |
||
| 117 | ); |
||
| 118 | } |
||
| 119 | |||
| 120 | foreach ($fileNodesDownload as $item) { |
||
| 121 | |||
| 122 | $xlinkNS = "http://www.w3.org/1999/xlink"; |
||
| 123 | $mextNS = "http://slub-dresden.de/mets"; |
||
| 124 | |||
| 125 | $flocat = $xpath->query('mets:FLocat', $item); |
||
| 126 | if ($flocat->length > 0) { |
||
| 127 | $href = $flocat->item(0)->getAttributeNS($xlinkNS, "href"); |
||
| 128 | } |
||
| 129 | |||
| 130 | $files[] = array( |
||
| 131 | 'id' => $item->getAttribute("ID"), |
||
| 132 | 'mimetype' => $item->getAttribute("MIMETYPE"), |
||
| 133 | 'href' => $href, |
||
| 134 | 'title' => $item->getAttributeNS($mextNS, "LABEL"), |
||
| 135 | 'archive' => ($item->getAttribute("USE") == 'ARCHIVE'), |
||
| 136 | 'download' => true, |
||
| 137 | 'deleted' => false, |
||
| 138 | ); |
||
| 139 | } |
||
| 140 | |||
| 141 | foreach ($fileNodesDeleted as $item) { |
||
| 142 | |||
| 143 | $xlinkNS = "http://www.w3.org/1999/xlink"; |
||
| 144 | $mextNS = "http://slub-dresden.de/mets"; |
||
| 145 | |||
| 146 | $flocat = $xpath->query('mets:FLocat', $item); |
||
| 147 | if ($flocat->length > 0) { |
||
| 148 | $href = $flocat->item(0)->getAttributeNS($xlinkNS, "href"); |
||
| 149 | } |
||
| 150 | |||
| 151 | $files[] = array( |
||
| 152 | 'id' => $item->getAttribute("ID"), |
||
| 153 | 'mimetype' => $item->getAttribute("MIMETYPE"), |
||
| 154 | 'href' => $href, |
||
| 155 | 'title' => $item->getAttributeNS($mextNS, "LABEL"), |
||
| 156 | 'archive' => ($item->getAttribute("USE") == 'ARCHIVE'), |
||
| 157 | 'download' => false, |
||
| 158 | 'deleted' => true, |
||
| 159 | ); |
||
| 160 | } |
||
| 161 | |||
| 162 | return $files; |
||
| 163 | |||
| 167 |