ByInvitationSignUpUserHandler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 6
dl 0
loc 49
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __invoke() 0 13 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\SignUp;
14
15
use BenGorUser\User\Domain\Model\Exception\UserDoesNotExistException;
16
use BenGorUser\User\Domain\Model\UserPassword;
17
use BenGorUser\User\Domain\Model\UserPasswordEncoder;
18
use BenGorUser\User\Domain\Model\UserRepository;
19
use BenGorUser\User\Domain\Model\UserToken;
20
21
/**
22
 * By invitation sign up user user command handler class.
23
 *
24
 * @author Beñat Espiña <[email protected]>
25
 * @author Gorka Laucirica <[email protected]>
26
 */
27
class ByInvitationSignUpUserHandler
28
{
29
    /**
30
     * The user password encoder.
31
     *
32
     * @var UserPasswordEncoder
33
     */
34
    private $encoder;
35
36
    /**
37
     * The user repository.
38
     *
39
     * @var UserRepository
40
     */
41
    private $userRepository;
42
43
    /**
44
     * Constructor.
45
     *
46
     * @param UserRepository      $aUserRepository The user repository
47
     * @param UserPasswordEncoder $anEncoder       The password encoder
48
     */
49
    public function __construct(UserRepository $aUserRepository, UserPasswordEncoder $anEncoder)
50
    {
51
        $this->userRepository = $aUserRepository;
52
        $this->encoder = $anEncoder;
53
    }
54
55
    /**
56
     * Handles the given command.
57
     *
58
     * @param ByInvitationSignUpUserCommand $aCommand The command
59
     *
60
     * @throws UserDoesNotExistException when the user does not exist
61
     */
62
    public function __invoke(ByInvitationSignUpUserCommand $aCommand)
63
    {
64
        $user = $this->userRepository->userOfInvitationToken(
65
            new UserToken($aCommand->invitationToken())
66
        );
67
        if (null === $user) {
68
            throw new UserDoesNotExistException();
69
        }
70
        $user->changePassword(UserPassword::fromPlain($aCommand->password(), $this->encoder));
71
        $user->acceptInvitation();
72
73
        $this->userRepository->persist($user);
74
    }
75
}
76