1 | <?php |
||||
2 | |||||
3 | declare(strict_types=1); |
||||
4 | |||||
5 | namespace App\User; |
||||
6 | |||||
7 | use Yiisoft\Access\AccessCheckerInterface; |
||||
8 | use Yiisoft\User\CurrentUser; |
||||
9 | |||||
10 | final class UserService |
||||
11 | { |
||||
12 | private CurrentUser $currentUser; |
||||
13 | private UserRepository $repository; |
||||
14 | private AccessCheckerInterface $accessChecker; |
||||
15 | |||||
16 | public function __construct(CurrentUser $currentUser, UserRepository $repository, AccessCheckerInterface $accessChecker) |
||||
17 | { |
||||
18 | $this->currentUser = $currentUser; |
||||
19 | $this->repository = $repository; |
||||
20 | $this->accessChecker = $accessChecker; |
||||
21 | } |
||||
22 | |||||
23 | public function getUser(): ?User |
||||
24 | { |
||||
25 | return $this->repository->findIdentity($this->currentUser->getId()); |
||||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() It seems like
$this->currentUser->getId() can also be of type null ; however, parameter $id of App\User\UserRepository::findIdentity() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
26 | } |
||||
27 | |||||
28 | public function hasPermission(string $permission): bool |
||||
29 | { |
||||
30 | $userId = $this->currentUser->getId(); |
||||
31 | return null !== $userId && $this->accessChecker->userHasPermission($userId, $permission); |
||||
32 | } |
||||
33 | } |
||||
34 |