Passed
Push — main ( 06cd81...bfbca3 )
by Karl
19:32 queued 13:14
created

UserRepository::upgradePassword()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 5
c 1
b 0
f 1
dl 0
loc 9
rs 10
cc 2
nc 2
nop 2
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
class UserRepository extends ServiceEntityRepository implements PasswordUpgraderInterface
16
{
17
    public function __construct(ManagerRegistry $registry)
18
    {
19
        parent::__construct($registry, User::class);
20
    }
21
22
    /**
23
     * Used to upgrade (rehash) the user's password automatically over time.
24
     */
25
    public function upgradePassword(PasswordAuthenticatedUserInterface $user, string $newHashedPassword): void
26
    {
27
        if (!$user instanceof User) {
28
            throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', $user::class));
29
        }
30
31
        $user->setPassword($newHashedPassword);
32
        $this->getEntityManager()->persist($user);
33
        $this->getEntityManager()->flush();
34
    }
35
36
    //    /**
37
    //     * @return User[] Returns an array of User objects
38
    //     */
39
    //    public function findByExampleField($value): array
40
    //    {
41
    //        return $this->createQueryBuilder('u')
42
    //            ->andWhere('u.exampleField = :val')
43
    //            ->setParameter('val', $value)
44
    //            ->orderBy('u.id', 'ASC')
45
    //            ->setMaxResults(10)
46
    //            ->getQuery()
47
    //            ->getResult()
48
    //        ;
49
    //    }
50
51
    //    public function findOneBySomeField($value): ?User
52
    //    {
53
    //        return $this->createQueryBuilder('u')
54
    //            ->andWhere('u.exampleField = :val')
55
    //            ->setParameter('val', $value)
56
    //            ->getQuery()
57
    //            ->getOneOrNullResult()
58
    //        ;
59
    //    }
60
}
61