Completed
Push — master ( 582c1a...3b0dd6 )
by Beñat
05:18 queued 47s
created

PurgeOutdatedRememberPasswordTokensUserHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 8 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\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
            $user->cleanRememberPasswordToken();
51
            $this->repository->persist($user);
52
        }
53
    }
54
}
55