UserRetrieveApplication   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 8
c 1
b 0
f 0
dl 0
loc 28
ccs 10
cts 10
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A serve() 0 13 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Uxmp\Core\Api\Settings;
6
7
use Psr\Http\Message\ResponseInterface;
8
use Psr\Http\Message\ServerRequestInterface;
9
use Teapot\StatusCode\Http;
10
use Uxmp\Core\Api\Lib\Message\JsonEnabledResponseInterface;
11
use Uxmp\Core\Api\Lib\ResultItemFactoryInterface;
12
use Uxmp\Core\Component\User\PrivilegeCheckerInterface;
13
use Uxmp\Core\Orm\Repository\UserRepositoryInterface;
14
15
/**
16
 * User retrieval
17
 */
18
final class UserRetrieveApplication extends AbstractSettingsApplication
19
{
20 2
    public function __construct(
21
        private readonly UserRepositoryInterface $userRepository,
22
        PrivilegeCheckerInterface $privilegeChecker,
23
        private readonly ResultItemFactoryInterface $resultItemFactory,
24
    ) {
25 2
        parent::__construct(
26 2
            $privilegeChecker
27 2
        );
28
    }
29
30
    /**
31
     * @param array<string, scalar> $args
32
     */
33 2
    protected function serve(
34
        ServerRequestInterface $request,
35
        JsonEnabledResponseInterface $response,
36
        array $args
37
    ): ResponseInterface {
38 2
        $user = $this->userRepository->find((int) ($args['userId'] ?? 0));
39
40 2
        if ($user === null) {
41 1
            return $response->withStatus(Http::NOT_FOUND);
42
        }
43
44 1
        return $response->withJson(
45 1
            $this->resultItemFactory->createUserListItem($user)
46 1
        );
47
    }
48
}
49