Passed
Push — main ( 3d6de0...a0d988 )
by Daniel
03:41
created

AbstractFavoriteApplication::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 0
dl 0
loc 3
ccs 1
cts 1
cp 1
rs 10
c 1
b 0
f 1
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Uxmp\Core\Api\User;
6
7
use Psr\Http\Message\ServerRequestInterface;
8
use Uxmp\Core\Api\AbstractApiApplication;
9
use Uxmp\Core\Component\Favorite\FavoriteAbleInterface;
10
use Uxmp\Core\Orm\Repository\SongRepositoryInterface;
11
12
abstract class AbstractFavoriteApplication extends AbstractApiApplication
13
{
14 5
    protected function __construct(
15
        private SongRepositoryInterface $songRepository
16
    ) {
17 5
    }
18
19
    /**
20
     * @param array<string, scalar> $args
21
     */
22 5
    protected function getItem(
23
        ServerRequestInterface $request,
24
        array $args
25
    ): ?FavoriteAbleInterface {
26
        /** @var array<string, mixed> $body */
27 5
        $body = $request->getParsedBody();
28
29 5
        $itemId = (int) ($body['itemId'] ?? 0);
30
31 5
        return match ((string) ($args['type'] ?? '')) {
32 5
            'song' => $this->songRepository->find($itemId),
33 5
            default => null,
34
        };
35
    }
36
}
37