AbstractSettingsApplication   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 11 2
A __construct() 0 3 1
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\Message\JsonEnabledResponseInterface;
12
use Uxmp\Core\Api\Lib\Middleware\SessionValidatorMiddleware;
13
use Uxmp\Core\Component\User\PrivilegeCheckerInterface;
14
15
/**
16
 * User list retrieval
17
 */
18
abstract class AbstractSettingsApplication extends AbstractApiApplication
19
{
20 9
    public function __construct(
21
        private readonly PrivilegeCheckerInterface $privilegeChecker
22
    ) {
23 9
    }
24
25
    /**
26
     * @param array<string, scalar> $args
27
     *
28
     * @throws AccessViolation
29
     */
30 9
    protected function run(
31
        ServerRequestInterface $request,
32
        JsonEnabledResponseInterface $response,
33
        array $args
34
    ): ResponseInterface {
35 9
        $user = $request->getAttribute(SessionValidatorMiddleware::USER);
36 9
        if (!$this->privilegeChecker->isAdmin($user)) {
37 1
            throw new AccessViolation();
38
        }
39
40 8
        return $this->serve($request, $response, $args);
41
    }
42
43
    /**
44
     * @param array<string, scalar> $args
45
     */
46
    abstract protected function serve(
47
        ServerRequestInterface $request,
48
        JsonEnabledResponseInterface $response,
49
        array $args
50
    ): ResponseInterface;
51
}
52