| Conditions | 4 |
| Paths | 4 |
| Total Lines | 33 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 17 |
| CRAP Score | 4 |
| Changes | 0 | ||
| 1 | <?php |
||
| 20 | 5 | public function update( |
|
| 21 | AlbumInterface $album, |
||
| 22 | AudioFileInterface $audioFile, |
||
| 23 | ): void { |
||
| 24 | 5 | $image = $audioFile->getAlbumCover(); |
|
| 25 | 5 | if ($image !== null) { |
|
| 26 | 4 | $extension = match ($image['image_mime']) { |
|
| 27 | 1 | 'image/jpeg' => 'jpg', |
|
| 28 | 1 | 'image/png' => 'png', |
|
| 29 | 1 | 'image/gif' => 'gif', |
|
| 30 | 1 | default => null, |
|
| 31 | }; |
||
| 32 | |||
| 33 | 4 | if ($extension === null) { |
|
| 34 | 1 | return; |
|
| 35 | } |
||
| 36 | |||
| 37 | 3 | $destination = sprintf( |
|
| 38 | '%s/img/album', |
||
| 39 | 3 | $this->config->getAssetPath() |
|
| 40 | ); |
||
| 41 | |||
| 42 | 3 | $filename = sprintf( |
|
| 43 | '%s/%s.%s', |
||
| 44 | $destination, |
||
| 45 | 3 | $album->getMbid(), |
|
| 46 | $extension |
||
| 47 | ); |
||
| 48 | |||
| 49 | 3 | if (!file_exists($filename)) { |
|
| 50 | 3 | file_put_contents($filename, $image['data']); |
|
| 51 | |||
| 52 | 3 | $this->artistCoverUpdater->update($album->getArtist()); |
|
| 53 | } |
||
| 57 |