AbstractUserRepository   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
supportsClass() 0 1 ?
A add() 0 5 1
A findByUsername() 0 4 1
A findByEmailAddress() 0 4 1
A save() 0 4 1
A delete() 0 5 1
A findByPasswordResetToken() 0 4 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
    public function add(User $user): void
13
    {
14
        $this->getEntityManager()->persist($user);
15
        $this->getEntityManager()->flush();
16
    }
17
18
    public function findByUsername(string $username): ?User
19
    {
20
        return $this->findOneBy(['username' => $username]);
21
    }
22
23
    public function findByEmailAddress(string $emailAddress): ?User
24
    {
25
        return $this->findOneBy(['email' => $emailAddress]);
26
    }
27
28
    abstract public function supportsClass(string $class): bool;
29
30
    public function save(User $user): void
31
    {
32
        $this->getEntityManager()->flush();
33
    }
34
35
    public function delete(User $user): void
36
    {
37
        $this->getEntityManager()->remove($user);
38
        $this->getEntityManager()->flush();
39
    }
40
41
    public function findByPasswordResetToken(PasswordResetToken $token): ?User
42
    {
43
        return $this->findOneBy(['passwordResetToken' => $token->getToken()]);
44
    }
45
}
46