Passed
Push — main ( 3d11c7...dcd309 )
by Daniel
14:22
created

AbstractSettingsApplication::__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 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
c 1
b 0
f 0
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 Uxmp\Core\Api\AbstractApiApplication;
10
use Uxmp\Core\Api\Lib\Exception\AccessViolation;
11
use Uxmp\Core\Api\Lib\Middleware\SessionValidatorMiddleware;
12
use Uxmp\Core\Component\User\PrivilegeCheckerInterface;
13
14
/**
15
 * User list retrieval
16
 */
17
abstract class AbstractSettingsApplication extends AbstractApiApplication
18
{
19 2
    public function __construct(
20
        private readonly PrivilegeCheckerInterface $privilegeChecker
21
    ) {
22
    }
23
24
    /**
25
     * @param array<string, scalar> $args
26
     *
27
     * @throws AccessViolation
28
     */
29 2
    protected function run(
30
        ServerRequestInterface $request,
31
        ResponseInterface $response,
32
        array $args
33
    ): ResponseInterface {
34 2
        $user = $request->getAttribute(SessionValidatorMiddleware::USER);
35 2
        if (!$this->privilegeChecker->isAdmin($user)) {
36 1
            throw new AccessViolation();
37
        }
38
39 1
        return $this->asJson(
40
            $response,
41 1
            $this->serve($request, $args)
42
        );
43
    }
44
45
    /**
46
     * @param array<string, scalar> $args
47
     *
48
     * @return array<mixed>
49
     * }
50
     */
51
    abstract protected function serve(
52
        ServerRequestInterface $request,
53
        array $args
54
    ): array;
55
}
56