| Conditions | 17 |
| Paths | 18 |
| Total Lines | 55 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| 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 |
||
| 73 | private function getAuthors() { |
||
| 74 | $authors = $this->xml->xpath('./mods:name[./mods:role/mods:roleTerm[@type="code" and @authority="marcrelator"]="aut"]'); |
||
| 75 | |||
| 76 | // Get "author" and "author_sorting" again if that was too sophisticated. |
||
| 77 | if (empty($authors)) { |
||
| 78 | // Get all names which do not have any role term assigned and assume these are authors. |
||
| 79 | $authors = $this->xml->xpath('./mods:name[not(./mods:role)]'); |
||
| 80 | } |
||
| 81 | if (!empty($authors)) { |
||
| 82 | for ($i = 0, $j = count($authors); $i < $j; $i++) { |
||
| 83 | $authors[$i]->registerXPathNamespace('mods', 'http://www.loc.gov/mods/v3'); |
||
| 84 | |||
| 85 | $identifier = $authors[$i]->xpath('./mods:name/mods:nameIdentifier[@type="orcid"]'); |
||
| 86 | if (!empty((string) $identifier[0])) { |
||
| 87 | $profile = new Profile((string) $identifier[0]); |
||
| 88 | $this->metadata['author'][$i] = $profile->getFullName(); |
||
| 89 | } else { |
||
| 90 | // Check if there is a display form. |
||
| 91 | if (($displayForm = $authors[$i]->xpath('./mods:displayForm'))) { |
||
| 92 | $this->metadata['author'][$i] = (string) $displayForm[0]; |
||
| 93 | } elseif (($nameParts = $authors[$i]->xpath('./mods:namePart'))) { |
||
| 94 | $name = []; |
||
| 95 | $k = 4; |
||
| 96 | foreach ($nameParts as $namePart) { |
||
| 97 | if ( |
||
| 98 | isset($namePart['type']) |
||
| 99 | && (string) $namePart['type'] == 'family' |
||
| 100 | ) { |
||
| 101 | $name[0] = (string) $namePart; |
||
| 102 | } elseif ( |
||
| 103 | isset($namePart['type']) |
||
| 104 | && (string) $namePart['type'] == 'given' |
||
| 105 | ) { |
||
| 106 | $name[1] = (string) $namePart; |
||
| 107 | } elseif ( |
||
| 108 | isset($namePart['type']) |
||
| 109 | && (string) $namePart['type'] == 'termsOfAddress' |
||
| 110 | ) { |
||
| 111 | $name[2] = (string) $namePart; |
||
| 112 | } elseif ( |
||
| 113 | isset($namePart['type']) |
||
| 114 | && (string) $namePart['type'] == 'date' |
||
| 115 | ) { |
||
| 116 | $name[3] = (string) $namePart; |
||
| 117 | } else { |
||
| 118 | $name[$k] = (string) $namePart; |
||
| 119 | } |
||
| 120 | $k++; |
||
| 121 | } |
||
| 122 | ksort($name); |
||
| 123 | $this->metadata['author'][$i] = trim(implode(', ', $name)); |
||
| 124 | } |
||
| 125 | // Append "valueURI" to name using Unicode unit separator. |
||
| 126 | if (isset($authors[$i]['valueURI'])) { |
||
| 127 | $this->metadata['author'][$i] .= chr(31) . (string) $authors[$i]['valueURI']; |
||
| 128 | } |
||
| 249 |