UserService::hasPermission()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\User;
6
7
use Yiisoft\Access\AccessCheckerInterface;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Access\AccessCheckerInterface 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...
8
use Yiisoft\User\CurrentUser;
0 ignored issues
show
Bug introduced by
The type Yiisoft\User\CurrentUser 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
final class UserService
11
{
12
    public function __construct(
13
        private CurrentUser $currentUser,
14
        private UserRepository $repository,
15
        private AccessCheckerInterface $accessChecker
16
    ) {
17
    }
18
19
    public function getUser(): ?User
20
    {
21
        $userId = $this->currentUser->getId();
22
23
        if ($userId === null) {
24
            return null;
25
        }
26
27
        return $this->repository->findById($this->currentUser->getId());
28
    }
29
30
    public function hasPermission(string $permission): bool
31
    {
32
        $userId = $this->currentUser->getId();
33
34
        return null !== $userId && $this->accessChecker->userHasPermission($userId, $permission);
35
    }
36
}
37