Code Duplication    Length = 18-22 lines in 4 locations

src/Doctrine/User/UserRepository.php 4 locations

@@ 30-48 (lines=19) @@
27
    }
28
29
    /** @return UserEntity */
30
    public function findByEmail(string $email)
31
    {
32
        $result = $this->createQueryBuilder('u')
33
            ->where('u.email = :email')
34
            ->setParameter('email', $email)
35
            ->getQuery()
36
            ->getResult();
37
38
39
        if ($result && $result[0]) {
40
            /** @var UserEntityInterface $user */
41
            $user = $result[0];
42
            $user->setGroupRepository($this->container->get(GroupRepositoryInterface::class));
43
            $user->setSessionRepository($this->container->get(SessionRepositoryInterface::class));
44
            return $user;
45
        }
46
47
        return null;
48
    }
49
50
    /** @return UserEntity */
51
    public function findById(int $id)
@@ 51-68 (lines=18) @@
48
    }
49
50
    /** @return UserEntity */
51
    public function findById(int $id)
52
    {
53
        $result = $this->createQueryBuilder('u')
54
            ->where('u.id = :id')
55
            ->setParameter('id', $id)
56
            ->getQuery()
57
            ->getResult();
58
59
        if ($result && $result[0]) {
60
            /** @var UserEntityInterface $user */
61
            $user = $result[0];
62
            $user->setGroupRepository($this->container->get(GroupRepositoryInterface::class));
63
            $user->setSessionRepository($this->container->get(SessionRepositoryInterface::class));
64
            return $user;
65
        }
66
67
        return null;
68
    }
69
70
    /** @return UserEntityInterface[] */
71
    public function findByGroupId(int $id)
@@ 71-89 (lines=19) @@
68
    }
69
70
    /** @return UserEntityInterface[] */
71
    public function findByGroupId(int $id)
72
    {
73
        $result = $this->createQueryBuilder('u')
74
            ->where('u.groupId = :groupId')
75
            ->setParameter('groupId', $id)
76
            ->getQuery()
77
            ->getResult();
78
79
        if ($result && $result[0]) {
80
            /** @var UserEntityInterface $user */
81
            foreach ($result as $user) {
82
                $user->setGroupRepository($this->container->get(GroupRepositoryInterface::class));
83
                $user->setSessionRepository($this->container->get(SessionRepositoryInterface::class));
84
            }
85
            return $result;
86
        }
87
88
        return [];
89
    }
90
91
    /** @return UserEntityInterface */
92
    public function findByResetPasswordToken(string $token)
@@ 92-113 (lines=22) @@
89
    }
90
91
    /** @return UserEntityInterface */
92
    public function findByResetPasswordToken(string $token)
93
    {
94
        if (empty($token)) {
95
            return null;
96
        }
97
98
        $result = $this->createQueryBuilder('u')
99
            ->where('u.passwordResetToken = :token')
100
            ->setParameter('token', $token)
101
            ->getQuery()
102
            ->getResult();
103
104
        if ($result && $result[0]) {
105
            /** @var UserEntityInterface $user */
106
            $user = $result[0];
107
            $user->setGroupRepository($this->container->get(GroupRepositoryInterface::class));
108
            $user->setSessionRepository($this->container->get(SessionRepositoryInterface::class));
109
            return $user;
110
        }
111
112
        return null;
113
    }
114
115
    public function save(UserEntityInterface $user)
116
    {