Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
9.09% |
1 / 11 |
|
25.00% |
1 / 4 |
CRAP | |
0.00% |
0 / 1 |
UserRepository | |
9.09% |
1 / 11 |
|
25.00% |
1 / 4 |
43.81 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
add | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
remove | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
upgradePassword | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace App\Repository; |
4 | |
5 | use App\Entity\User; |
6 | use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; |
7 | use Doctrine\Persistence\ManagerRegistry; |
8 | use Symfony\Component\Security\Core\Exception\UnsupportedUserException; |
9 | use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; |
10 | use Symfony\Component\Security\Core\User\PasswordUpgraderInterface; |
11 | |
12 | /** |
13 | * @extends ServiceEntityRepository<User> |
14 | * |
15 | * @method User|null find($id, $lockMode = null, $lockVersion = null) |
16 | * @method User|null findOneBy(array $criteria, array $orderBy = null) |
17 | * @method User[] findAll() |
18 | * @method User[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) |
19 | */ |
20 | class UserRepository extends ServiceEntityRepository implements PasswordUpgraderInterface |
21 | { |
22 | public function __construct(ManagerRegistry $registry) |
23 | { |
24 | parent::__construct($registry, User::class); |
25 | } |
26 | |
27 | public function add(User $entity, bool $flush = false): void |
28 | { |
29 | $this->getEntityManager()->persist($entity); |
30 | |
31 | if ($flush) { |
32 | $this->getEntityManager()->flush(); |
33 | } |
34 | } |
35 | |
36 | public function remove(User $entity, bool $flush = false): void |
37 | { |
38 | $this->getEntityManager()->remove($entity); |
39 | |
40 | if ($flush) { |
41 | $this->getEntityManager()->flush(); |
42 | } |
43 | } |
44 | |
45 | /** |
46 | * Used to upgrade (rehash) the user's password automatically over time. |
47 | */ |
48 | public function upgradePassword(PasswordAuthenticatedUserInterface $user, string $newHashedPassword): void |
49 | { |
50 | if (!$user instanceof User) { |
51 | throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', \get_class($user))); |
52 | } |
53 | |
54 | $user->setPassword($newHashedPassword); |
55 | |
56 | $this->add($user, true); |
57 | } |
58 | |
59 | // /** |
60 | // * @return User[] Returns an array of User objects |
61 | // */ |
62 | // public function findByExampleField($value): array |
63 | // { |
64 | // return $this->createQueryBuilder('u') |
65 | // ->andWhere('u.exampleField = :val') |
66 | // ->setParameter('val', $value) |
67 | // ->orderBy('u.id', 'ASC') |
68 | // ->setMaxResults(10) |
69 | // ->getQuery() |
70 | // ->getResult() |
71 | // ; |
72 | // } |
73 | |
74 | // public function findOneBySomeField($value): ?User |
75 | // { |
76 | // return $this->createQueryBuilder('u') |
77 | // ->andWhere('u.exampleField = :val') |
78 | // ->setParameter('val', $value) |
79 | // ->getQuery() |
80 | // ->getOneOrNullResult() |
81 | // ; |
82 | // } |
83 | } |