Completed
Push — master ( 617c71...61acac )
by Gorka
13s
created

ResendInvitationUserHandler::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
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\Invite;
14
15
use BenGorUser\User\Domain\Model\Exception\UserDoesNotExistException;
16
use BenGorUser\User\Domain\Model\UserEmail;
17
use BenGorUser\User\Domain\Model\UserRepository;
18
19
/**
20
 * Resend invitation user command handler class.
21
 *
22
 * @author Beñat Espiña <[email protected]>
23
 */
24 View Code Duplication
class ResendInvitationUserHandler
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25
{
26
    /**
27
     * The user repository.
28
     *
29
     * @var UserRepository
30
     */
31
    private $repository;
32
33
    /**
34
     * Constructor.
35
     *
36
     * @param UserRepository $aRepository The user repository
37
     */
38
    public function __construct(UserRepository $aRepository)
39
    {
40
        $this->repository = $aRepository;
41
    }
42
43
    /**
44
     * Handles the given command.
45
     *
46
     * @param ResendInvitationUserCommand $aCommand The command
47
     *
48
     * @throws UserDoesNotExistException when the user does not exist
49
     */
50
    public function __invoke(ResendInvitationUserCommand $aCommand)
51
    {
52
        $user = $this->repository->userOfEmail(new UserEmail($aCommand->email()));
53
        if (null === $user) {
54
            throw new UserDoesNotExistException();
55
        }
56
        $user->regenerateInvitationToken();
57
58
        $this->repository->persist($user);
59
    }
60
}
61