| Conditions | 6 |
| Paths | 24 |
| Total Lines | 55 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 31 | public function transform($item) |
||
| 32 | { |
||
| 33 | $manga =& $item['manga']; |
||
| 34 | |||
| 35 | $rating = (is_numeric($item['rating'])) |
||
| 36 | ? intval(2 * $item['rating']) |
||
| 37 | : '-'; |
||
| 38 | |||
| 39 | $total_chapters = ($manga['chapter_count'] > 0) |
||
| 40 | ? $manga['chapter_count'] |
||
| 41 | : '-'; |
||
| 42 | |||
| 43 | $total_volumes = ($manga['volume_count'] > 0) |
||
| 44 | ? $manga['volume_count'] |
||
| 45 | : '-'; |
||
| 46 | |||
| 47 | $map = [ |
||
| 48 | 'id' => $item['id'], |
||
| 49 | 'chapters' => [ |
||
| 50 | 'read' => $item['chapters_read'], |
||
| 51 | 'total' => $total_chapters |
||
| 52 | ], |
||
| 53 | 'volumes' => [ |
||
| 54 | 'read' => $item['volumes_read'], |
||
| 55 | 'total' => $total_volumes |
||
| 56 | ], |
||
| 57 | 'manga' => [ |
||
| 58 | 'title' => $manga['romaji_title'], |
||
| 59 | 'alternate_title' => NULL, |
||
| 60 | 'slug' => $manga['id'], |
||
| 61 | 'url' => 'https://hummingbird.me/manga/' . $manga['id'], |
||
| 62 | 'type' => $manga['manga_type'], |
||
| 63 | 'image' => $manga['poster_image_thumb'], |
||
| 64 | 'genres' => $manga['genres'], |
||
| 65 | ], |
||
| 66 | 'reading_status' => $item['status'], |
||
| 67 | 'notes' => $item['notes'], |
||
| 68 | 'rereading' => (bool)$item['rereading'], |
||
| 69 | 'reread' => $item['reread_count'], |
||
| 70 | 'user_rating' => $rating |
||
| 71 | ]; |
||
| 72 | |||
| 73 | if (array_key_exists('english_title', $manga)) |
||
| 74 | { |
||
| 75 | $diff = levenshtein($manga['romaji_title'], $manga['english_title']); |
||
| 76 | |||
| 77 | // If the titles are REALLY similar, don't bother showing both |
||
| 78 | if ($diff >= 5) |
||
| 79 | { |
||
| 80 | $map['manga']['alternate_title'] = $manga['english_title']; |
||
| 81 | } |
||
| 82 | } |
||
| 83 | |||
| 84 | return $map; |
||
| 85 | } |
||
| 86 | |||
| 125 | // End of MangaListTransformer.php |