| Total Complexity | 42 |
| Total Lines | 286 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
Complex classes like RisReader 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 RisReader, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 27 | class RisReader |
||
| 28 | { |
||
| 29 | public static $tagMap = [ |
||
| 30 | 'FN' => 'File Name', |
||
| 31 | 'VR' => 'Version Number', |
||
| 32 | 'PT' => 'Publication Type', |
||
| 33 | 'AU' => 'Author', |
||
| 34 | 'AF' => 'Author Full Name', |
||
| 35 | 'BA' => 'Book Author', |
||
| 36 | 'BF' => 'Book Author Full Name', |
||
| 37 | 'CA' => 'Group Author', |
||
| 38 | 'GP' => 'Book Group Author', |
||
| 39 | 'BE' => 'Editor', |
||
| 40 | 'TI' => 'Document Title', |
||
| 41 | 'SO' => 'Publication Name', |
||
| 42 | 'SE' => 'Book Series Title', |
||
| 43 | 'BS' => 'Book Series Subtitle', |
||
| 44 | 'LA' => 'Language', |
||
| 45 | 'DT' => 'Document Type', |
||
| 46 | 'CT' => 'Conference Title', |
||
| 47 | 'CY' => 'Conference Date', |
||
| 48 | 'CL' => 'Conference Location', |
||
| 49 | 'SP' => 'Conference Sponsors', |
||
| 50 | 'HO' => 'Conference Host', |
||
| 51 | 'DE' => 'Author Keywords', |
||
| 52 | 'ID' => 'Keywords Plus', |
||
| 53 | 'AB' => 'Abstract', |
||
| 54 | 'C1' => 'Author Address', |
||
| 55 | 'RP' => 'Reprint Address', |
||
| 56 | 'EM' => 'E-mail Address', |
||
| 57 | 'RI' => 'ResearcherID Number', |
||
| 58 | 'OI' => 'ORCID Identifier', |
||
| 59 | 'FU' => 'Funding Agency and Grant Number', |
||
| 60 | 'FX' => 'Funding Text', |
||
| 61 | 'CR' => 'Cited References', |
||
| 62 | 'NR' => 'Cited Reference Count', |
||
| 63 | 'TC' => 'WoS Times Cited Count', |
||
| 64 | 'Z9' => 'Total Times Cited Count', |
||
| 65 | 'U1' => 'Usage Count las 180 days', |
||
| 66 | 'U2' => 'Usage Count since 2013', |
||
| 67 | 'PU' => 'Publisher', |
||
| 68 | 'PI' => 'Publisher City', |
||
| 69 | 'PA' => 'Publisher Address', |
||
| 70 | 'SN' => 'ISSN', |
||
| 71 | 'EI' => 'eISSN', |
||
| 72 | 'BN' => 'ISBN', |
||
| 73 | 'J9' => 'Character-29 Source Abbreviation', |
||
| 74 | 'JI' => 'ISO Source Abbreviation', |
||
| 75 | 'PD' => 'Publication Date', |
||
| 76 | 'PY' => 'Year Published', |
||
| 77 | 'VL' => 'Volume', |
||
| 78 | 'IS' => 'Issue', |
||
| 79 | 'SI' => 'Special Issue', |
||
| 80 | 'PN' => 'Part Number', |
||
| 81 | 'SU' => 'Supplement', |
||
| 82 | 'MA' => 'Meeting Abstract', |
||
| 83 | 'BP' => 'Beginning Page', |
||
| 84 | 'EP' => 'Ending Page', |
||
| 85 | 'AR' => 'Article Number', |
||
| 86 | 'DI' => 'DOI', |
||
| 87 | 'D2' => 'Book DOI', |
||
| 88 | 'EA' => 'Early access date', |
||
| 89 | 'EY' => 'Early access year', |
||
| 90 | 'PG' => 'Page Count', |
||
| 91 | 'P2' => 'Chapter Count', |
||
| 92 | 'WC' => 'WoS Categories', |
||
| 93 | 'SC' => 'Research Areas', |
||
| 94 | 'GA' => 'Document Delivery Number', |
||
| 95 | 'PM' => 'PubMed ID', |
||
| 96 | 'UT' => 'Accession Number', |
||
| 97 | 'OA' => 'Open Access Indicator', |
||
| 98 | 'HP' => 'ESI Hot Paper', |
||
| 99 | 'HC' => 'ESI Highly Cited Paper', |
||
| 100 | 'DA' => 'Date generated', |
||
| 101 | 'ER' => 'End of Record', |
||
| 102 | 'EF' => 'End of File' |
||
| 103 | ]; |
||
| 104 | |||
| 105 | |||
| 106 | public static $publicationTypes = [ |
||
| 107 | 'J' => 'Journal', |
||
| 108 | 'B' => 'Book', |
||
| 109 | 'S' => 'Series', |
||
| 110 | 'P' => 'Patent' |
||
| 111 | ]; |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Gets the full tag name |
||
| 115 | * |
||
| 116 | * @param string $tag |
||
| 117 | */ |
||
| 118 | public static function tagToTagName($tag) |
||
| 119 | { |
||
| 120 | return str_replace(" ", "-", strtolower(self::$tagMap[$tag])); |
||
| 121 | } |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @param string $filePath |
||
| 125 | * @return array |
||
| 126 | */ |
||
| 127 | protected function readFile($filePath, $contentOnly = false) |
||
| 128 | { |
||
| 129 | $separator = "\r\n"; |
||
| 130 | |||
| 131 | if ($contentOnly) { |
||
| 132 | $line = strtok($filePath, $separator); |
||
| 133 | } else { |
||
| 134 | $flags = FILE_SKIP_EMPTY_LINES | FILE_TEXT; |
||
| 135 | $lines = file($filePath, $flags); |
||
| 136 | } |
||
| 137 | |||
| 138 | $currentTag = ''; |
||
| 139 | $risRecords = []; |
||
| 140 | $risRecord = []; |
||
| 141 | $recordIndex = 0; |
||
| 142 | |||
| 143 | if ($contentOnly) { |
||
| 144 | |||
| 145 | while ($line !== false) { |
||
| 146 | if (mb_detect_encoding($line) == 'UTF-8') { |
||
| 147 | $line = utf8_decode($line); |
||
| 148 | if (strpos($line, '?') === 0) { |
||
| 149 | $line = substr($line, 1); |
||
| 150 | } |
||
| 151 | } |
||
| 152 | |||
| 153 | $tempTag = trim(substr($line, 0, 2)); |
||
| 154 | if ($tempTag == 'EF') { |
||
| 155 | // End of file |
||
| 156 | break; |
||
| 157 | } |
||
| 158 | |||
| 159 | if ($tempTag == 'ER') { |
||
| 160 | $risRecords[$recordIndex] = $risRecord; |
||
| 161 | $risRecord = []; |
||
| 162 | $recordIndex += 1; |
||
| 163 | } else { |
||
| 164 | if ($tempTag) { |
||
| 165 | $currentTag = $tempTag; |
||
| 166 | } |
||
| 167 | |||
| 168 | $line = substr($line, 2); |
||
| 169 | |||
| 170 | if ($currentTag && array_key_exists($currentTag, self::$tagMap)) { |
||
| 171 | $risRecord[$currentTag][] = trim($line); |
||
| 172 | } |
||
| 173 | } |
||
| 174 | $line = strtok($separator); |
||
| 175 | } |
||
| 176 | |||
| 177 | } else { |
||
| 178 | foreach($lines as $line) { |
||
| 179 | |||
| 180 | if (mb_detect_encoding($line) == 'UTF-8') { |
||
| 181 | $line = utf8_decode($line); |
||
| 182 | if (strpos($line, '?') === 0) { |
||
| 183 | $line = substr($line, 1); |
||
| 184 | } |
||
| 185 | } |
||
| 186 | |||
| 187 | $tempTag = trim(substr($line, 0, 2)); |
||
| 188 | if ($tempTag == 'EF') { |
||
| 189 | // End of file |
||
| 190 | break; |
||
| 191 | } |
||
| 192 | |||
| 193 | if ($tempTag == 'ER') { |
||
| 194 | $risRecords[$recordIndex] = $risRecord; |
||
| 195 | $risRecord = []; |
||
| 196 | $recordIndex += 1; |
||
| 197 | } else { |
||
| 198 | if ($tempTag) { |
||
| 199 | $currentTag = $tempTag; |
||
| 200 | } |
||
| 201 | |||
| 202 | $line = substr($line, 2); |
||
| 203 | |||
| 204 | if ($currentTag && array_key_exists($currentTag, self::$tagMap)) { |
||
| 205 | $risRecord[$currentTag][] = trim($line); |
||
| 206 | } |
||
| 207 | } |
||
| 208 | } |
||
| 209 | } |
||
| 210 | |||
| 211 | return $risRecords; |
||
| 212 | } |
||
| 213 | |||
| 214 | public function createRisRecords() { |
||
| 215 | |||
| 216 | } |
||
| 217 | |||
| 218 | public function parseFile($filePath, $contentOnly = false) |
||
| 279 | } |
||
| 280 | |||
| 281 | /** |
||
| 282 | * @param array $risRecord |
||
| 283 | */ |
||
| 284 | public function risRecordToXML($risRecord) |
||
| 313 | } |
||
| 314 | |||
| 315 | } |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths