Passed
Push — main ( 7dcca1...e70bce )
by Daniel
04:22
created

ArtistHandler   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 7
c 1
b 0
f 0
dl 0
loc 20
ccs 9
cts 9
cp 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Uxmp\Core\Component\Playlist\MediaAddition\Handler;
6
7
use Uxmp\Core\Orm\Repository\ArtistRepositoryInterface;
8
9
/**
10
 * Adds songs of an artist to the list of songs
11
 */
12
final readonly class ArtistHandler implements HandlerInterface
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_READONLY, expecting T_CLASS on line 12 at column 6
Loading history...
13
{
14 1
    public function __construct(
15
        private ArtistRepositoryInterface $artistRepository,
16
    ) {
17 1
    }
18
19
    /**
20
     * Adds all eligible song ids of the artists' album to the songList array
21
     *
22
     * @param array<int> $songList
23
     */
24 1
    public function handle(int $mediaId, array &$songList): void
25
    {
26 1
        $artist = $this->artistRepository->find($mediaId);
27 1
        if ($artist !== null) {
28 1
            foreach ($artist->getAlbums() as $album) {
29 1
                foreach ($album->getDiscs() as $disc) {
30 1
                    foreach ($disc->getSongs() as $song) {
31 1
                        $songList[] = $song->getId();
32
                    }
33
                }
34
            }
35
        }
36
    }
37
}
38