yiisoft /
demo
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace App\Auth; |
||
| 6 | |||
| 7 | use App\User\UserRepository; |
||
| 8 | use Throwable; |
||
| 9 | use Yiisoft\Auth\IdentityInterface; |
||
|
0 ignored issues
–
show
|
|||
| 10 | use Yiisoft\User\CurrentUser; |
||
|
0 ignored issues
–
show
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 11 | |||
| 12 | final class AuthService |
||
| 13 | { |
||
| 14 | public function __construct( |
||
| 15 | private CurrentUser $currentUser, |
||
| 16 | private UserRepository $userRepository, |
||
| 17 | private IdentityRepository $identityRepository, |
||
| 18 | ) { |
||
| 19 | } |
||
| 20 | |||
| 21 | public function login(string $login, string $password): bool |
||
| 22 | { |
||
| 23 | $user = $this->userRepository->findByLoginWithAuthIdentity($login); |
||
| 24 | |||
| 25 | if ($user === null || !$user->validatePassword($password)) { |
||
| 26 | return false; |
||
| 27 | } |
||
| 28 | |||
| 29 | return $this->currentUser->login($user->getIdentity()); |
||
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @throws Throwable |
||
| 34 | */ |
||
| 35 | public function logout(): bool |
||
| 36 | { |
||
| 37 | $identity = $this->currentUser->getIdentity(); |
||
| 38 | |||
| 39 | if ($identity instanceof Identity) { |
||
| 40 | $identity->regenerateCookieLoginKey(); |
||
| 41 | $this->identityRepository->save($identity); |
||
| 42 | } |
||
| 43 | |||
| 44 | return $this->currentUser->logout(); |
||
| 45 | } |
||
| 46 | |||
| 47 | public function getIdentity(): IdentityInterface |
||
| 48 | { |
||
| 49 | return $this->currentUser->getIdentity(); |
||
| 50 | } |
||
| 51 | |||
| 52 | public function isGuest(): bool |
||
| 53 | { |
||
| 54 | return $this->currentUser->isGuest(); |
||
| 55 | } |
||
| 56 | } |
||
| 57 |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths