| Conditions | 4 |
| Paths | 4 |
| Total Lines | 26 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 20 |
| Changes | 0 | ||
| 1 | <?php |
||
| 19 | public function update( |
||
| 20 | AlbumInterface $album, |
||
| 21 | array $metadata |
||
| 22 | ): void { |
||
| 23 | $destination = realpath($this->config->getAssetPath() . '/img/album'); |
||
| 24 | |||
| 25 | // search in comments |
||
| 26 | /** @var null|array{image_mime: string, data: string} $image */ |
||
| 27 | $image = $metadata['comments']['picture'][0] ?? null; |
||
| 28 | if ($image !== null) { |
||
| 29 | $filename = $destination . '/' . $album->getMbid(); |
||
| 30 | if (!file_exists($filename)) { |
||
| 31 | $extension = match ($image['image_mime']) { |
||
| 32 | 'image/jpeg' => 'jpg', |
||
| 33 | 'image/png' => 'png', |
||
| 34 | 'image/gif' => 'gif', |
||
| 35 | default => null, |
||
| 36 | }; |
||
| 37 | |||
| 38 | if ($extension === null) { |
||
| 39 | return; |
||
| 40 | } |
||
| 41 | |||
| 42 | file_put_contents($filename. '.' . $extension, $image['data']); |
||
| 43 | |||
| 44 | $this->artistCoverUpdater->update($album->getArtist()); |
||
| 45 | } |
||
| 49 |