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

ArtItemIdentifier   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 9
c 1
b 0
f 0
dl 0
loc 22
ccs 11
cts 11
cp 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Uxmp\Core\Component\Art;
6
7
use Uxmp\Core\Orm\Repository\AlbumRepositoryInterface;
8
use Uxmp\Core\Orm\Repository\ArtistRepositoryInterface;
9
10
/**
11
 * Identifies art items by their `art-id` (like artist-16, album-666, ...)
12
 */
13
final readonly class ArtItemIdentifier implements ArtItemIdentifierInterface
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_READONLY, expecting T_CLASS on line 13 at column 6
Loading history...
14
{
15 4
    public function __construct(
16
        private AlbumRepositoryInterface $albumRepository,
17
        private ArtistRepositoryInterface $artistRepository,
18
    ) {
19 4
    }
20
21 4
    public function identify(
22
        string $item
23
    ): ?CachableArtItemInterface {
24 4
        $data = explode('-', $item);
25 4
        if (count($data) !== 2) {
26 1
            return null;
27
        }
28
29 3
        [$itemType, $itemId] = $data;
30
31 3
        return match ($itemType) {
32 3
            default => null,
33 3
            'album' => $this->albumRepository->find((int) $itemId),
34 3
            'artist' => $this->artistRepository->find((int) $itemId),
35 3
        };
36
    }
37
}
38