We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Total Complexity | 47 | 
| Total Lines | 224 | 
| Duplicated Lines | 0 % | 
| Changes | 6 | ||
| Bugs | 0 | Features | 0 | 
Complex classes like Mods often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Mods, and based on these observations, apply Extract Interface, too.
| 1 | <?php  | 
            ||
| 25 | class Mods implements \Kitodo\Dlf\Common\MetadataInterface  | 
            ||
| 26 | { | 
            ||
| 27 | /**  | 
            ||
| 28 | * The metadata XML  | 
            ||
| 29 | *  | 
            ||
| 30 | * @var \SimpleXMLElement  | 
            ||
| 31 | **/  | 
            ||
| 32 | private $xml;  | 
            ||
| 33 | |||
| 34 | /**  | 
            ||
| 35 | * The metadata array  | 
            ||
| 36 | *  | 
            ||
| 37 | * @var array  | 
            ||
| 38 | **/  | 
            ||
| 39 | private $metadata;  | 
            ||
| 40 | |||
| 41 | /**  | 
            ||
| 42 | * This extracts the essential MODS metadata from XML  | 
            ||
| 43 | *  | 
            ||
| 44 | * @access public  | 
            ||
| 45 | *  | 
            ||
| 46 | * @param \SimpleXMLElement $xml: The XML to extract the metadata from  | 
            ||
| 47 | * @param array &$metadata: The metadata array to fill  | 
            ||
| 48 | *  | 
            ||
| 49 | * @return void  | 
            ||
| 50 | */  | 
            ||
| 51 | public function extractMetadata(\SimpleXMLElement $xml, array &$metadata)  | 
            ||
| 64 | }  | 
            ||
| 65 | |||
| 66 | /**  | 
            ||
| 67 | * Get "author" and "author_sorting".  | 
            ||
| 68 | *  | 
            ||
| 69 | * @access private  | 
            ||
| 70 | *  | 
            ||
| 71 | * @return void  | 
            ||
| 72 | */  | 
            ||
| 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 | }  | 
            ||
| 129 | }  | 
            ||
| 130 | }  | 
            ||
| 131 | }  | 
            ||
| 132 | }  | 
            ||
| 133 | |||
| 134 | /**  | 
            ||
| 135 | * Get holder.  | 
            ||
| 136 | *  | 
            ||
| 137 | * @access private  | 
            ||
| 138 | *  | 
            ||
| 139 | * @return void  | 
            ||
| 140 | */  | 
            ||
| 141 |     private function getHolders() { | 
            ||
| 142 |         $holders = $this->xml->xpath('./mods:name[./mods:role/mods:roleTerm[@type="code" and @authority="marcrelator"]="prv"]'); | 
            ||
| 143 | |||
| 144 |         if (!empty($holders)) { | 
            ||
| 145 |             for ($i = 0, $j = count($holders); $i < $j; $i++) { | 
            ||
| 146 |                 $holders[$i]->registerXPathNamespace('mods', 'http://www.loc.gov/mods/v3'); | 
            ||
| 147 | |||
| 148 |                 //$identifier = $holders[$i]->xpath('./mods:nameIdentifier'); | 
            ||
| 149 |                 if (1 != 1) { | 
            ||
| 150 | //TODO: reading VIAF API  | 
            ||
| 151 |                 } else { | 
            ||
| 152 | // Check if there is a display form.  | 
            ||
| 153 |                     if (($displayForm = $holders[$i]->xpath('./mods:displayForm'))) { | 
            ||
| 154 | $this->metadata['holder'][$i] = (string) $displayForm[0];  | 
            ||
| 155 |                     } elseif (($nameParts = $holders[$i]->xpath('./mods:namePart'))) { | 
            ||
| 156 | $name = [];  | 
            ||
| 157 | $k = 4;  | 
            ||
| 158 |                         foreach ($nameParts as $namePart) { | 
            ||
| 159 | if (  | 
            ||
| 160 | isset($namePart['type'])  | 
            ||
| 161 | && (string) $namePart['type'] == 'family'  | 
            ||
| 162 |                             ) { | 
            ||
| 163 | $name[0] = (string) $namePart;  | 
            ||
| 164 | } elseif (  | 
            ||
| 165 | isset($namePart['type'])  | 
            ||
| 166 | && (string) $namePart['type'] == 'given'  | 
            ||
| 167 |                             ) { | 
            ||
| 168 | $name[1] = (string) $namePart;  | 
            ||
| 169 | } elseif (  | 
            ||
| 170 | isset($namePart['type'])  | 
            ||
| 171 | && (string) $namePart['type'] == 'termsOfAddress'  | 
            ||
| 172 |                             ) { | 
            ||
| 173 | $name[2] = (string) $namePart;  | 
            ||
| 174 | } elseif (  | 
            ||
| 175 | isset($namePart['type'])  | 
            ||
| 176 | && (string) $namePart['type'] == 'date'  | 
            ||
| 177 |                             ) { | 
            ||
| 178 | $name[3] = (string) $namePart;  | 
            ||
| 179 |                             } else { | 
            ||
| 180 | $name[$k] = (string) $namePart;  | 
            ||
| 181 | }  | 
            ||
| 182 | $k++;  | 
            ||
| 183 | }  | 
            ||
| 184 | ksort($name);  | 
            ||
| 185 |                         $this->metadata['holder'][$i] = trim(implode(', ', $name)); | 
            ||
| 186 | }  | 
            ||
| 187 | }  | 
            ||
| 188 | }  | 
            ||
| 189 | }  | 
            ||
| 190 | }  | 
            ||
| 191 | |||
| 192 | /**  | 
            ||
| 193 | * Get "place" and "place_sorting".  | 
            ||
| 194 | *  | 
            ||
| 195 | * @access private  | 
            ||
| 196 | *  | 
            ||
| 197 | * @return void  | 
            ||
| 198 | */  | 
            ||
| 199 |     private function getPlaces() { | 
            ||
| 211 | }  | 
            ||
| 212 | }  | 
            ||
| 213 | }  | 
            ||
| 214 | }  | 
            ||
| 215 | |||
| 216 | /**  | 
            ||
| 217 | * Get "year" and "year_sorting".  | 
            ||
| 218 | *  | 
            ||
| 219 | * @access private  | 
            ||
| 220 | *  | 
            ||
| 221 | * @return void  | 
            ||
| 222 | */  | 
            ||
| 223 |     private function getYears() { | 
            ||
| 249 | }  | 
            ||
| 250 | }  | 
            ||
| 251 | }  | 
            ||
| 254 |