Passed
Pull Request — master (#2138)
by Janko
27:56 queued 16:09
created

AccessCheck   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
c 1
b 0
f 0
dl 0
loc 52
ccs 23
cts 23
cp 1
rs 10
wmc 11

3 Methods

Rating   Name   Duplication   Size   Complexity  
A checkUserAccess() 0 26 5
A isFeatureGranted() 0 18 5
A __construct() 0 3 1
1
<?php
2
3
namespace Stu\Module\Control;
4
5
use Override;
0 ignored issues
show
Bug introduced by
The type Override was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Stu\Lib\AccountNotVerifiedException;
7
use Stu\Module\Config\StuConfigInterface;
8
use Stu\Module\PlayerSetting\Lib\UserEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Module\PlayerSetting\Lib\UserEnum was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
class AccessCheck implements AccessCheckInterface
11
{
12 11
    public function __construct(
13
        private StuConfigInterface $stuConfig
14 11
    ) {}
15
16 9
    #[Override]
17
    public function checkUserAccess(
18
        ControllerInterface $controller,
19
        GameControllerInterface $game
20
    ): bool {
21
22 9
        if ($controller instanceof NoAccessCheckControllerInterface) {
23 1
            return true;
24
        }
25
26 8
        if ($game->getUser()->getState() === UserEnum::USER_STATE_ACCOUNT_VERIFICATION) {
27 1
            throw new AccountNotVerifiedException();
28
        }
29
30 7
        if (!$controller instanceof AccessCheckControllerInterface) {
31 1
            return true;
32
        }
33
34 6
        $feature = $controller->getFeatureIdentifier();
35 6
        if ($this->isFeatureGranted($game->getUser()->getId(), $feature, $game)) {
36 2
            return true;
37
        }
38
39 4
        $game->addInformation('[b][color=#ff2626]Aktion nicht möglich, Spieler ist nicht berechtigt![/color][/b]');
40
41 4
        return false;
42
    }
43
44 7
    #[Override]
45
    public function isFeatureGranted(int $userId, AccessGrantedFeatureEnum $feature, GameControllerInterface $game): bool
46
    {
47 7
        if ($game->isAdmin()) {
48 1
            return true;
49
        }
50
51 6
        $grantedFeatures = $this->stuConfig->getGameSettings()->getGrantedFeatures();
52 6
        foreach ($grantedFeatures as $entry) {
53
            if (
54 5
                $entry['feature'] === $feature->name
0 ignored issues
show
Bug introduced by
The property name does not seem to exist on Stu\Module\Control\AccessGrantedFeatureEnum.
Loading history...
55 5
                && in_array($userId, $entry['userIds'])
56
            ) {
57 1
                return true;
58
            }
59
        }
60
61 5
        return false;
62
    }
63
}
64