Passed
Push — master ( 6efd44...835b8c )
by Luiz Kim
14:33 queued 12:23
created

UserRepository   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

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

5 Methods

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