Completed
Push — master ( e22fb5...191f29 )
by
unknown
12s
created

AbstractUserRepository::findByEmailAddress()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace SumoCoders\FrameworkMultiUserBundle\User;
4
5
use Doctrine\ORM\EntityRepository;
6
use SumoCoders\FrameworkMultiUserBundle\Security\PasswordResetToken;
7
use SumoCoders\FrameworkMultiUserBundle\User\Interfaces\User;
8
use SumoCoders\FrameworkMultiUserBundle\User\Interfaces\UserRepository as UserRepositoryInterface;
9
10
abstract class AbstractUserRepository extends EntityRepository implements UserRepositoryInterface
11
{
12
    /**
13
     * @param User $user
14
     */
15
    public function add(User $user)
16
    {
17
        $this->getEntityManager()->persist($user);
18
        $this->getEntityManager()->flush();
19
    }
20
21
    /**
22
     * @param string $username
23
     *
24
     * @return null|User
25
     */
26
    public function findByUsername($username)
27
    {
28
        return $this->findOneBy(['username' => $username]);
29
    }
30
31
    /**
32
     * @param string $emailAddress
33
     *
34
     * @return User|null
35
     */
36
    public function findByEmailAddress($emailAddress)
37
    {
38
        return $this->findOneBy(['email' => $emailAddress]);
39
    }
40
41
    /**
42
     * @param string $class
43
     *
44
     * @return bool
45
     */
46
    abstract public function supportsClass($class);
47
48
    /**
49
     * @param User $user
50
     */
51
    public function save(User $user)
52
    {
53
        $this->getEntityManager()->flush();
54
    }
55
56
    /**
57
     * @param User $user
58
     */
59
    public function delete(User $user)
60
    {
61
        $this->getEntityManager()->remove($user);
62
        $this->getEntityManager()->flush();
63
    }
64
65
    /**
66
     * @param PasswordResetToken $token
67
     *
68
     * @return null|User
69
     */
70
    public function findByPasswordResetToken(PasswordResetToken $token)
71
    {
72
        return $this->findOneBy(['passwordResetToken' => $token->getToken()]);
73
    }
74
}
75