ChangePasswordHandler   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A __invoke() 0 11 1
1
<?php
2
3
/*
4
 * This file has been created by developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * another great project.
7
 * You can find more information about us on https://bitbag.io and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace BitBag\SyliusVueStorefrontPlugin\CommandHandler\User;
14
15
use BitBag\SyliusVueStorefrontPlugin\Command\User\ChangePassword;
16
use BitBag\SyliusVueStorefrontPlugin\Sylius\Provider\LoggedInShopUserProviderInterface;
17
use Sylius\Component\User\Repository\UserRepositoryInterface;
18
use Sylius\Component\User\Security\UserPasswordEncoderInterface;
19
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
20
21
final class ChangePasswordHandler implements MessageHandlerInterface
22
{
23
    /** @var LoggedInShopUserProviderInterface */
24
    private $loggedInShopUserProvider;
25
26
    /** @var UserPasswordEncoderInterface */
27
    private $userPasswordEncoder;
28
29
    /** @var UserRepositoryInterface */
30
    private $shopUserRepository;
31
32
    public function __construct(
33
        LoggedInShopUserProviderInterface $loggedInShopUserProvider,
34
        UserPasswordEncoderInterface $userPasswordEncoder,
35
        UserRepositoryInterface $shopUserRepository
36
    ) {
37
        $this->loggedInShopUserProvider = $loggedInShopUserProvider;
38
        $this->userPasswordEncoder = $userPasswordEncoder;
39
        $this->shopUserRepository = $shopUserRepository;
40
    }
41
42
    public function __invoke(ChangePassword $changePassword): void
43
    {
44
        $shopUser = $this->loggedInShopUserProvider->provide();
45
        $shopUser->setPlainPassword($changePassword->newPassword());
46
47
        $encodedPassword = $this->userPasswordEncoder->encode($shopUser);
48
49
        $shopUser->setPassword($encodedPassword);
50
51
        $this->shopUserRepository->add($shopUser);
52
    }
53
}
54