EnableUserHandler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 5
dl 0
loc 39
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 12 2
1
<?php
2
3
/*
4
 * This file is part of the BenGorUser package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace BenGorUser\User\Application\Command\Enable;
14
15
use BenGorUser\User\Domain\Model\Exception\UserTokenNotFoundException;
16
use BenGorUser\User\Domain\Model\UserRepository;
17
use BenGorUser\User\Domain\Model\UserToken;
18
19
/**
20
 * Enable user command handler class.
21
 *
22
 * @author Beñat Espiña <[email protected]>
23
 * @author Gorka Laucirica <[email protected]>
24
 */
25
class EnableUserHandler
26
{
27
    /**
28
     * The user repository.
29
     *
30
     * @var UserRepository
31
     */
32
    private $repository;
33
34
    /**
35
     * Constructor.
36
     *
37
     * @param UserRepository $aRepository The user repository
38
     */
39
    public function __construct(UserRepository $aRepository)
40
    {
41
        $this->repository = $aRepository;
42
    }
43
44
    /**
45
     * Handles the given command.
46
     *
47
     * @param EnableUserCommand $aCommand The command
48
     *
49
     * @throws UserTokenNotFoundException when the user token does not exist
50
     */
51
    public function __invoke(EnableUserCommand $aCommand)
52
    {
53
        $confirmationToken = $aCommand->confirmationToken();
54
55
        $user = $this->repository->userOfConfirmationToken(new UserToken($confirmationToken));
56
        if (null === $user) {
57
            throw new UserTokenNotFoundException();
58
        }
59
        $user->enableAccount();
60
61
        $this->repository->persist($user);
62
    }
63
}
64