| Conditions | 7 |
| Paths | 18 |
| Total Lines | 61 |
| Code Lines | 42 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 2 |
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 |
||
| 30 | public function transform($item) |
||
| 31 | { |
||
| 32 | $anime =& $item['anime']; |
||
| 33 | $genres = $this->linearize_genres($item['anime']['genres']); |
||
| 34 | |||
| 35 | $rating = NULL; |
||
| 36 | if ($item['rating']['type'] === 'advanced') |
||
| 37 | { |
||
| 38 | $rating = (is_numeric($item['rating']['value'])) |
||
| 39 | ? intval(2 * $item['rating']['value']) |
||
| 40 | : '-'; |
||
| 41 | } |
||
| 42 | |||
| 43 | $total_episodes = (is_numeric($anime['episode_count'])) |
||
| 44 | ? $anime['episode_count'] |
||
| 45 | : '-'; |
||
| 46 | |||
| 47 | $alternate_title = NULL; |
||
| 48 | if (array_key_exists('alternate_title', $anime)) |
||
| 49 | { |
||
| 50 | // If the alternate title is very similar, or |
||
| 51 | // a subset of the main title, don't list the |
||
| 52 | // alternate title |
||
| 53 | $not_subset = stripos($anime['title'], $anime['alternate_title']) === FALSE; |
||
| 54 | $diff = levenshtein($anime['title'], $anime['alternate_title']); |
||
| 55 | if ($not_subset && $diff >= 5) |
||
| 56 | { |
||
| 57 | $alternate_title = $anime['alternate_title']; |
||
| 58 | } |
||
| 59 | } |
||
| 60 | |||
| 61 | return [ |
||
| 62 | 'episodes' => [ |
||
| 63 | 'watched' => $item['episodes_watched'], |
||
| 64 | 'total' => $total_episodes, |
||
| 65 | 'length' => $anime['episode_length'], |
||
| 66 | ], |
||
| 67 | 'airing' => [ |
||
| 68 | 'status' => $anime['status'], |
||
| 69 | 'started' => $anime['started_airing'], |
||
| 70 | 'ended' => $anime['finished_airing'] |
||
| 71 | ], |
||
| 72 | 'anime' => [ |
||
| 73 | 'age_rating' => $anime['age_rating'], |
||
| 74 | 'title' => $anime['title'], |
||
| 75 | 'alternate_title' => $alternate_title, |
||
| 76 | 'slug' => $anime['slug'], |
||
| 77 | 'url' => $anime['url'], |
||
| 78 | 'type' => $anime['show_type'], |
||
| 79 | 'image' => $anime['cover_image'], |
||
| 80 | 'genres' => $genres, |
||
| 81 | ], |
||
| 82 | 'id' => $item['id'], |
||
| 83 | 'watching_status' => $item['status'], |
||
| 84 | 'notes' => $item['notes'], |
||
| 85 | 'rewatching' => (bool) $item['rewatching'], |
||
| 86 | 'rewatched' => $item['rewatched_times'], |
||
| 87 | 'user_rating' => $rating, |
||
| 88 | 'private' => (bool) $item['private'], |
||
| 89 | ]; |
||
| 90 | } |
||
| 91 | |||
| 144 | // End of AnimeListTransformer.php |