Completed
Pull Request — master (#138)
by Łukasz
18:55
created

GenerateVerificationTokenHandler   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 34
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 11 1
1
<?php
2
3
namespace Sylius\ShopApiPlugin\Handler;
4
5
use Sylius\Component\Core\Model\ShopUserInterface;
6
use Sylius\Component\User\Repository\UserRepositoryInterface;
7
use Sylius\Component\User\Security\Generator\GeneratorInterface;
8
use Sylius\ShopApiPlugin\Command\GenerateVerificationToken;
9
use Webmozart\Assert\Assert;
10
11
final class GenerateVerificationTokenHandler
12
{
13
    /**
14
     * @var UserRepositoryInterface
15
     */
16
    private $userRepository;
17
18
    /**
19
     * @var GeneratorInterface
20
     */
21
    private $tokenGenerator;
22
23
    /**
24
     * @param UserRepositoryInterface $userRepository
25
     * @param GeneratorInterface $tokenGenerator
26
     */
27
    public function __construct(UserRepositoryInterface $userRepository, GeneratorInterface $tokenGenerator)
28
    {
29
        $this->userRepository = $userRepository;
30
        $this->tokenGenerator = $tokenGenerator;
31
    }
32
33
    public function handle(GenerateVerificationToken $generateVerificationToken)
34
    {
35
        $email = $generateVerificationToken->email();
36
37
        /** @var ShopUserInterface $user */
38
        $user = $this->userRepository->findOneByEmail($email);
39
40
        Assert::notNull($user, sprintf('User with %s email has not been found.', $email));
41
42
        $user->setEmailVerificationToken($this->tokenGenerator->generate());
43
    }
44
}
45