Passed
Push — main ( 024f60...c8b1e7 )
by Daniel
03:34
created

AlbumDeleter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 0
dl 0
loc 5
ccs 1
cts 1
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Uxmp\Core\Component\Album;
6
7
use Uxmp\Core\Component\Artist\ArtistCoverUpdaterInterface;
8
use Uxmp\Core\Component\Config\ConfigProviderInterface;
9
use Uxmp\Core\Orm\Model\AlbumInterface;
10
use Uxmp\Core\Orm\Repository\AlbumRepositoryInterface;
11
12
final class AlbumDeleter implements AlbumDeleterInterface
13
{
14 1
    public function __construct(
15
        private AlbumRepositoryInterface $albumRepository,
16
        private ConfigProviderInterface $config,
17
        private ArtistCoverUpdaterInterface $artistCoverUpdater,
18
    ) {
19 1
    }
20
21 1
    public function delete(AlbumInterface $album): void
22
    {
23 1
        $path = sprintf(
24 1
            '%s/img/%s/%s.jpg',
25 1
            $this->config->getAssetPath(),
26 1
            $album->getArtItemType(),
27 1
            $album->getArtItemId()
28
        );
29
30 1
        if (file_exists($path)) {
31 1
            unlink($path);
32
        }
33
34 1
        $artist = $album->getArtist();
35
36 1
        $this->albumRepository->delete($album);
37
38 1
        $this->artistCoverUpdater->update($artist);
39 1
    }
40
}
41