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