AbstractUserRepository::delete()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
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
    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