SubSonicSettingsRetrieveApplication   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 7
c 1
b 0
f 0
dl 0
loc 22
ccs 10
cts 10
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 15 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Uxmp\Core\Api\User\SubSonic;
6
7
use Psr\Http\Message\ResponseInterface;
8
use Psr\Http\Message\ServerRequestInterface;
9
use Uxmp\Core\Api\AbstractApiApplication;
10
use Uxmp\Core\Api\Lib\Message\JsonEnabledResponseInterface;
11
use Uxmp\Core\Api\Lib\Middleware\SessionValidatorMiddleware;
12
use Uxmp\Core\Component\Authentication\AccessKey\AccessKeyTypeEnum;
13
use Uxmp\Core\Component\SubSonic\AuthenticationProvider;
14
use Uxmp\Core\Orm\Model\UserInterface;
15
use Uxmp\Core\Orm\Repository\AccessKeyRepositoryInterface;
16
17
/**
18
 * Delivers the users subsonic api settings
19
 */
20
final class SubSonicSettingsRetrieveApplication extends AbstractApiApplication
21
{
22 2
    public function __construct(
23
        private readonly AccessKeyRepositoryInterface $accessKeyRepository,
24
    ) {
25 2
    }
26
27 2
    protected function run(
28
        ServerRequestInterface $request,
29
        JsonEnabledResponseInterface $response,
30
        array $args
31
    ): ResponseInterface {
32
        /** @var UserInterface $user */
33 2
        $user = $request->getAttribute(SessionValidatorMiddleware::USER);
34
35 2
        $accessKey = $this->accessKeyRepository->findOneBy([
36 2
            'user' => $user,
37 2
            'type_id' => AccessKeyTypeEnum::SUBSONIC,
38 2
        ]);
39
40 2
        return $response->withJson([
41 2
            'accessToken' => $accessKey?->getConfig()[AuthenticationProvider::CONFIG_KEY_TOKEN] ?? null,
42 2
        ]);
43
    }
44
}
45