yiisoft /
demo
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | declare(strict_types=1); |
||||||
| 4 | |||||||
| 5 | namespace App\User; |
||||||
| 6 | |||||||
| 7 | use App\Exception\BadRequestException; |
||||||
| 8 | use App\Queue\LoggingAuthorizationHandler; |
||||||
| 9 | use App\Queue\UserLoggedInMessage; |
||||||
| 10 | use Yiisoft\Auth\IdentityInterface; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 11 | use Yiisoft\Auth\IdentityRepositoryInterface; |
||||||
|
0 ignored issues
–
show
The type
Yiisoft\Auth\IdentityRepositoryInterface 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...
|
|||||||
| 12 | use Yiisoft\Definitions\Exception\InvalidConfigException; |
||||||
|
0 ignored issues
–
show
The type
Yiisoft\Definitions\Exce...\InvalidConfigException 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...
|
|||||||
| 13 | 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...
|
|||||||
| 14 | use Yiisoft\Queue\QueueFactoryInterface; |
||||||
|
0 ignored issues
–
show
The type
Yiisoft\Queue\QueueFactoryInterface 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...
|
|||||||
| 15 | |||||||
| 16 | final class UserService |
||||||
| 17 | { |
||||||
| 18 | private IdentityRepositoryInterface $identityRepository; |
||||||
| 19 | private CurrentUser $currentUser; |
||||||
| 20 | private QueueFactoryInterface $queueFactory; |
||||||
| 21 | |||||||
| 22 | public function __construct( |
||||||
| 23 | CurrentUser $currentUser, |
||||||
| 24 | IdentityRepositoryInterface $identityRepository, |
||||||
| 25 | QueueFactoryInterface $queueFactory |
||||||
| 26 | ) { |
||||||
| 27 | $this->currentUser = $currentUser; |
||||||
| 28 | $this->identityRepository = $identityRepository; |
||||||
| 29 | $this->queueFactory = $queueFactory; |
||||||
| 30 | } |
||||||
| 31 | |||||||
| 32 | /** |
||||||
| 33 | * @param string $login |
||||||
| 34 | * @param string $password |
||||||
| 35 | * |
||||||
| 36 | * @throws InvalidConfigException |
||||||
| 37 | * @throws BadRequestException |
||||||
| 38 | * |
||||||
| 39 | * @return IdentityInterface |
||||||
| 40 | */ |
||||||
| 41 | public function login(string $login, string $password): IdentityInterface |
||||||
| 42 | { |
||||||
| 43 | $identity = $this->identityRepository->findByLogin($login); |
||||||
|
0 ignored issues
–
show
|
|||||||
| 44 | if ($identity === null) { |
||||||
| 45 | throw new BadRequestException('No such user.'); |
||||||
| 46 | } |
||||||
| 47 | |||||||
| 48 | if (!$identity->validatePassword($password)) { |
||||||
| 49 | throw new BadRequestException('Invalid password.'); |
||||||
| 50 | } |
||||||
| 51 | |||||||
| 52 | if (!$this->currentUser->login($identity)) { |
||||||
| 53 | throw new BadRequestException(); |
||||||
| 54 | } |
||||||
| 55 | |||||||
| 56 | $identity->resetToken(); |
||||||
| 57 | $this->identityRepository->save($identity); |
||||||
| 58 | |||||||
| 59 | $queueMessage = new UserLoggedInMessage($identity->getId(), time()); |
||||||
| 60 | $this->queueFactory->get(LoggingAuthorizationHandler::CHANNEL)->push($queueMessage); |
||||||
|
0 ignored issues
–
show
|
|||||||
| 61 | |||||||
| 62 | return $identity; |
||||||
| 63 | } |
||||||
| 64 | |||||||
| 65 | public function logout(User $user): void |
||||||
| 66 | { |
||||||
| 67 | $user->resetToken(); |
||||||
|
0 ignored issues
–
show
The method
resetToken() does not exist on App\User\User.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||||
| 68 | $this->identityRepository->save($user); |
||||||
|
0 ignored issues
–
show
|
|||||||
| 69 | } |
||||||
| 70 | } |
||||||
| 71 |
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