| Total Complexity | 3 |
| Total Lines | 22 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 13 | final readonly class ArtItemIdentifier implements ArtItemIdentifierInterface |
||
|
|
|||
| 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 | }; |
|
| 38 |