Completed
Pull Request — master (#44)
by Beñat
02:18
created

__invoke()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
rs 9.4285
cc 3
eloc 6
nc 3
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\UserRepository;
16
17
/**
18
 * Purge outdated remember password tokens command handler class.
19
 *
20
 * @author Beñat Espiña <[email protected]>
21
 */
22
class PurgeOutdatedRememberPasswordTokensUserHandler
23
{
24
    /**
25
     * The user repository.
26
     *
27
     * @var UserRepository
28
     */
29
    private $repository;
30
31
    /**
32
     * Constructor.
33
     *
34
     * @param UserRepository $aRepository The user repository
35
     */
36
    public function __construct(UserRepository $aRepository)
37
    {
38
        $this->repository = $aRepository;
39
    }
40
41
    /**
42
     * Handles the given command.
43
     *
44
     * @param PurgeOutdatedRememberPasswordTokensUserCommand $aCommand The command
45
     */
46
    public function __invoke(PurgeOutdatedRememberPasswordTokensUserCommand $aCommand)
47
    {
48
        $users = $this->repository->all();
49
        foreach ($users as $user) {
50
            if ($user->isRememberPasswordTokenExpired()) {
51
                $user->cleanRememberPasswordToken();
52
            }
53
            $this->repository->persist($user);
54
        }
55
    }
56
}
57