| Conditions | 22 | 
| Paths | 41 | 
| Total Lines | 44 | 
| 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 | ||
| 17 | public function parse($record) | ||
| 18 |     { | ||
| 19 | if ($record instanceof SimpleXmlElement) | ||
| 20 |         { | ||
| 21 | $record = new QuiteSimpleXmlElement($record); | ||
| 22 | } | ||
| 23 | elseif (!$record instanceof QuiteSimpleXmlElement) | ||
| 24 |         { | ||
| 25 |             throw new \Exception('Invalid type given to Parser->parse. Expected SimpleXmlElement or QuiteSimpleXmlElement', 1); | ||
| 26 | } | ||
| 27 | |||
| 28 |         $leader = $record->text('marc:leader'); | ||
| 29 | |||
| 30 | //99999 ai a22999997c 4500 | ||
| 31 | |||
| 32 | $recordType = substr($leader, 6, 1); | ||
| 33 | |||
| 34 |         switch ($recordType) { | ||
| 35 | case 'a': // Language material | ||
| 36 | case 'c': // Notated music | ||
| 37 | case 'd': // Manuscript notated music | ||
| 38 | case 'e': // Cartographic material | ||
| 39 | case 'f': // Manuscript cartographic material | ||
| 40 | case 'g': // Projected medium | ||
| 41 | case 'i': // Nonmusical sound recording | ||
| 42 | case 'j': // Musical sound recording | ||
| 43 | case 'k': // Two-dimensional nonprojectable graphic | ||
| 44 | case 'm': // Computer file | ||
| 45 | case 'o': // Kit | ||
| 46 | case 'p': // Mixed materials | ||
| 47 | case 'r': // Three-dimensional artifact or naturally occurring object | ||
| 48 | case 't': // Manuscript language material | ||
| 49 | return new BibliographicRecord($record); | ||
| 50 | case 'z': | ||
| 51 | return new AuthorityRecord($record); | ||
| 52 | case 'u': // Unknown | ||
| 53 | case 'v': // Multipart item holdings | ||
| 54 | case 'x': // Single-part item holdings | ||
| 55 | case 'y': // Serial item holdings | ||
| 56 | return new HoldingsRecord($record); | ||
| 57 | default: | ||
| 58 |                 throw new ParserException("Unknown record type.\n\n------------------------\n" . $record->asXML() . "\n------------------------"); | ||
| 59 | } | ||
| 60 | } | ||
| 61 | } | ||
| 62 |