UserRepository   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 19
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A upgradePassword() 0 9 2
1
<?php
2
/*
3
 * Copyright (C) 2020  Jan Böhmer
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU Affero General Public License as published
7
 * by the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU Affero General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Affero General Public License
16
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17
 */
18
19
namespace App\Repository;
20
21
use App\Entity\User;
22
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
23
use Doctrine\Persistence\ManagerRegistry;
24
use function get_class;
25
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
26
use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;
27
use Symfony\Component\Security\Core\User\UserInterface;
28
29
/**
30
 * @method User|null find($id, $lockMode = null, $lockVersion = null)
31
 * @method User|null findOneBy(array $criteria, array $orderBy = null)
32
 * @method User[]    findAll()
33
 * @method User[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
34
 */
35
class UserRepository extends ServiceEntityRepository implements PasswordUpgraderInterface
36
{
37
    public function __construct(ManagerRegistry $registry)
38
    {
39
        parent::__construct($registry, User::class);
40
    }
41
42
    /**
43
     * Used to upgrade (rehash) the user's password automatically over time.
44
     */
45
    public function upgradePassword(UserInterface $user, string $newEncodedPassword): void
46
    {
47
        if (!$user instanceof User) {
48
            throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_class($user)));
49
        }
50
51
        $user->setPassword($newEncodedPassword);
52
        $this->_em->persist($user);
53
        $this->_em->flush();
54
    }
55
56
    /*
57
    public function findByExampleField($value)
58
    {
59
        return $this->createQueryBuilder('u')
60
            ->andWhere('u.exampleField = :val')
61
            ->setParameter('val', $value)
62
            ->orderBy('u.id', 'ASC')
63
            ->setMaxResults(10)
64
            ->getQuery()
65
            ->getResult()
66
        ;
67
    }
68
    */
69
70
    /*
71
    public function findOneBySomeField($value): ?User
72
    {
73
        return $this->createQueryBuilder('u')
74
            ->andWhere('u.exampleField = :val')
75
            ->setParameter('val', $value)
76
            ->getQuery()
77
            ->getOneOrNullResult()
78
        ;
79
    }
80
    */
81
}
82