Passed
Push — dev ( 374f50...1bdd7d )
by Janko
15:55 queued 25s
created

AccessCheck::checkUserAccess()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 8
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 18
ccs 0
cts 8
cp 0
crap 12
rs 10
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\Config\Init;
7
use Stu\Module\Config\StuConfigInterface;
8
9
class AccessCheck implements AccessCheckInterface
10
{
11 2
    public function __construct(
12
        private StuConfigInterface $stuConfig
13 2
    ) {}
14
15
    #[Override]
16
    public function checkUserAccess(
17
        ControllerInterface $controller,
18
        GameControllerInterface $game
19
    ): bool {
20
21
        if (!$controller instanceof AccessCheckControllerInterface) {
22
            return true;
23
        }
24
25
        $feature = $controller->getFeatureIdentifier();
26
        if ($this->isFeatureGranted($game->getUser()->getId(), $feature)) {
27
            return true;
28
        }
29
30
        $game->addInformation(_('[b][color=#ff2626]Aktion nicht möglich, Spieler ist nicht berechtigt![/color][/b]'));
31
32
        return false;
33
    }
34
35 1
    #[Override]
36
    public function isFeatureGranted(int $userId, AccessGrantedFeatureEnum $feature): bool
37
    {
38 1
        if (Init::getContainer()->get(GameControllerInterface::class)->isAdmin()) {
39
            return true;
40
        }
41
42 1
        $grantedFeatures = $this->stuConfig->getGameSettings()->getGrantedFeatures();
43 1
        foreach ($grantedFeatures as $entry) {
44
            if (
45 1
                $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...
46 1
                && in_array($userId, $entry['userIds'])
47
            ) {
48
                return true;
49
            }
50
        }
51
52 1
        return false;
53
    }
54
}
55