RevokeUserRoleHandler::__invoke()   A
last analyzed

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\RevokeRole;
14
15
use BenGorUser\User\Domain\Model\Exception\UserDoesNotExistException;
16
use BenGorUser\User\Domain\Model\UserId;
17
use BenGorUser\User\Domain\Model\UserRepository;
18
use BenGorUser\User\Domain\Model\UserRole;
19
20
/**
21
 * Revoke user role command handler class.
22
 *
23
 * @author Beñat Espiña <[email protected]>
24
 */
25 View Code Duplication
class RevokeUserRoleHandler
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...
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 RevokeUserRoleCommand $aCommand The command
48
     *
49
     * @throws UserDoesNotExistException when the user does not exist
50
     */
51
    public function __invoke(RevokeUserRoleCommand $aCommand)
52
    {
53
        $user = $this->repository->userOfId(new UserId($aCommand->id()));
54
        if (null === $user) {
55
            throw new UserDoesNotExistException();
56
        }
57
        $user->revoke(new UserRole($aCommand->role()));
58
59
        $this->repository->persist($user);
60
    }
61
}
62