userOfConfirmationToken()   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
rs 10
c 0
b 0
f 0
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\DoctrineORMBridge\Infrastructure\Persistence;
14
15
use BenGorUser\User\Domain\Model\User;
16
use BenGorUser\User\Domain\Model\UserEmail;
17
use BenGorUser\User\Domain\Model\UserId;
18
use BenGorUser\User\Domain\Model\UserRepository;
19
use BenGorUser\User\Domain\Model\UserToken;
20
use Doctrine\ORM\EntityRepository;
21
22
/**
23
 * Doctrine ORM user repository class.
24
 *
25
 * @author Beñat Espiña <[email protected]>
26
 * @author Gorka Laucirica <[email protected]>
27
 */
28
class DoctrineORMUserRepository extends EntityRepository implements UserRepository
29
{
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function userOfId(UserId $anId)
34
    {
35
        return $this->find($anId->id());
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function all()
42
    {
43
        return $this->findAll();
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function userOfEmail(UserEmail $anEmail)
50
    {
51
        return $this->findOneBy(['email.email' => $anEmail->email()]);
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function userOfConfirmationToken(UserToken $aConfirmationToken)
58
    {
59
        return $this->findOneBy(['confirmationToken.token' => $aConfirmationToken->token()]);
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function userOfInvitationToken(UserToken $anInvitationToken)
66
    {
67
        return $this->findOneBy(['invitationToken.token' => $anInvitationToken->token()]);
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    public function userOfRememberPasswordToken(UserToken $aRememberPasswordToken)
74
    {
75
        return $this->findOneBy(['rememberPasswordToken.token' => $aRememberPasswordToken->token()]);
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     */
81
    public function persist(User $aUser)
82
    {
83
        $this->getEntityManager()->persist($aUser);
84
    }
85
86
    /**
87
     * {@inheritdoc}
88
     */
89
    public function remove(User $aUser)
90
    {
91
        $this->getEntityManager()->remove($aUser);
92
    }
93
94
    /**
95
     * {@inheritdoc}
96
     */
97
    public function size()
98
    {
99
        $queryBuilder = $this->createQueryBuilder('u');
100
101
        return $queryBuilder
102
            ->select($queryBuilder->expr()->count('u.id'))
103
            ->getQuery()
104
            ->getSingleScalarResult();
105
    }
106
}
107