UserRepository::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace ControleOnline\Repository;
4
5
use ControleOnline\Entity\User;
6
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
0 ignored issues
show
Bug introduced by
The type Doctrine\Bundle\Doctrine...ServiceEntityRepository was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Bridge\Doctrine\...ser\UserLoaderInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Securi...asswordEncoderInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Doctrine\Persistence\ManagerRegistry;
0 ignored issues
show
Bug introduced by
The type Doctrine\Persistence\ManagerRegistry was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Symfony\Component\Security\Core\User\UserInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Security\Core\User\UserInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
12
/**
13
 * @method User|null find($id, $lockMode = null, $lockVersion = null)
14
 * @method User|null findOneBy(array $criteria, array $orderBy = null)
15
 * @method User[]    findAll()
16
 * @method User[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
17
 */
18
class UserRepository extends ServiceEntityRepository implements UserLoaderInterface
19
{
20
21
    public function __construct(ManagerRegistry $registry)
22
    {
23
        parent::__construct($registry, User::class);
24
    }
25
26
    public function loadUserByIdentifier(string $identifier): ?UserInterface
27
    {
28
        return $this->createQueryBuilder('u')
29
            ->andWhere('u.username = :identifier')
30
            ->setParameter('identifier', $identifier)
31
            ->getQuery()
32
            ->getOneOrNullResult();
33
    }
34
35
36
    public function updatePassword(string $email, string $password): ?User
37
    {
38
        if ($user = $this->findOneByEmail($email)) {
39
            $user->setPassword($password);
40
41
            $this->getEntityManager()->persist($user);
42
43
            $this->getEntityManager()->flush();
44
45
            return $user;
46
        }
47
    }
48
49
    public function getActiveUserByEmail($email)
50
    {
51
        return $this->createQueryBuilder('u')
52
            ->where('u.email  = :email')
53
            ->andwhere('u.active = 1')
54
            ->setParameter('email', $email)
55
            ->getQuery()->getOneOrNullResult();
56
    }
57
58
    public function loadUserByUsername($username)
59
    {
60
        return $this->createQueryBuilder('u')
61
            ->where('u.username  = :username')
62
            ->setParameter('username', $username)
63
            ->getQuery()->getOneOrNullResult();
64
    }
65
}
66