| Total Complexity | 7 |
| Total Lines | 55 |
| Duplicated Lines | 0 % |
| Coverage | 90.48% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 10 | class MediaInformationService |
||
| 11 | { |
||
| 12 | private $lastfmService; |
||
| 13 | |||
| 14 | 7 | public function __construct(LastfmService $lastfmService) |
|
| 15 | { |
||
| 16 | 7 | $this->lastfmService = $lastfmService; |
|
| 17 | 7 | } |
|
| 18 | |||
| 19 | /** |
||
| 20 | * Get extra information about an album from Last.fm. |
||
| 21 | * |
||
| 22 | * @return array|null The album info in an array format, or null on failure. |
||
| 23 | */ |
||
| 24 | 1 | public function getAlbumInformation(Album $album): ?array |
|
| 25 | { |
||
| 26 | 1 | if ($album->is_unknown) { |
|
| 27 | return null; |
||
| 28 | } |
||
| 29 | |||
| 30 | 1 | $info = $this->lastfmService->getAlbumInformation($album->name, $album->artist->name); |
|
| 31 | |||
| 32 | 1 | if ($info) { |
|
| 33 | 1 | event(new AlbumInformationFetched($album, $info)); |
|
| 34 | |||
| 35 | // The album may have been updated. |
||
| 36 | 1 | $album->refresh(); |
|
| 37 | 1 | $info['cover'] = $album->cover; |
|
| 38 | } |
||
| 39 | |||
| 40 | 1 | return $info; |
|
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Get extra information about an artist from Last.fm. |
||
| 45 | * |
||
| 46 | * @return array|null The artist info in an array format, or null on failure. |
||
| 47 | */ |
||
| 48 | 1 | public function getArtistInformation(Artist $artist): ?array |
|
| 65 | } |
||
| 66 | } |
||
| 67 |