Passed
Push — main ( 1d1c5b...83bc52 )
by Daniel
04:23
created

ArtistHandler::handle()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 6
c 1
b 0
f 0
nc 5
nop 2
dl 0
loc 8
ccs 7
cts 7
cp 1
crap 5
rs 9.6111
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 class ArtistHandler implements HandlerInterface
13
{
14 1
    public function __construct(
15
        private readonly ArtistRepositoryInterface $artistRepository,
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_STRING, expecting T_VARIABLE on line 15 at column 25
Loading history...
16
    ) {
17
    }
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