__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
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\PurgeOutdatedTokens;
14
15
use BenGorUser\User\Domain\Model\Exception\UserTokenNotFoundException;
16
use BenGorUser\User\Domain\Model\UserRepository;
17
18
/**
19
 * Purge outdated invitation tokens command handler class.
20
 *
21
 * @author Beñat Espiña <[email protected]>
22
 */
23
class PurgeOutdatedInvitationTokensUserHandler
24
{
25
    /**
26
     * The user repository.
27
     *
28
     * @var UserRepository
29
     */
30
    private $repository;
31
32
    /**
33
     * Constructor.
34
     *
35
     * @param UserRepository $aRepository The user repository
36
     */
37
    public function __construct(UserRepository $aRepository)
38
    {
39
        $this->repository = $aRepository;
40
    }
41
42
    /**
43
     * Handles the given command.
44
     *
45
     * @param PurgeOutdatedInvitationTokensUserCommand $aCommand The command
46
     */
47
    public function __invoke(PurgeOutdatedInvitationTokensUserCommand $aCommand)
48
    {
49
        $users = $this->repository->all();
50
        foreach ($users as $user) {
51
            try {
52
                $user->cleanInvitationToken();
53
            } catch (UserTokenNotFoundException $exception) {
54
                continue;
55
            }
56
            $this->repository->persist($user);
57
        }
58
    }
59
}
60