RemoveUserHandler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 4
dl 0
loc 36
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 9 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\Remove;
14
15
use BenGorUser\User\Domain\Model\Exception\UserDoesNotExistException;
16
use BenGorUser\User\Domain\Model\UserId;
17
use BenGorUser\User\Domain\Model\UserRepository;
18
19
/**
20
 * Remove user command handler class.
21
 *
22
 * @author Beñat Espiña <[email protected]>
23
 * @author Gorka Laucirica <[email protected]>
24
 */
25
class RemoveUserHandler
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 RemoveUserCommand $aCommand The command
48
     *
49
     * @throws UserDoesNotExistException when the user does not exist
50
     */
51
    public function __invoke(RemoveUserCommand $aCommand)
52
    {
53
        $user = $this->repository->userOfId(new UserId($aCommand->id()));
54
        if (null === $user) {
55
            throw new UserDoesNotExistException();
56
        }
57
58
        $this->repository->remove($user);
59
    }
60
}
61