Completed
Push — master ( 999f09...ad2afa )
by Petr
03:11
created

UserRepository::findByEmail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Rottenwood\KingdomBundle\Entity\Infrastructure;
4
5
use Rottenwood\KingdomBundle\Entity\Room;
6
use Rottenwood\KingdomBundle\Entity\User;
7
8
class UserRepository extends AbstractRepository {
1 ignored issue
show
Coding Style introduced by
As per PSR2, the opening brace for this class should be on a new line.
Loading history...
9
10
    /**
11
     * @param int $userId
12
     * @return User|null
13
     */
14
    public function findById($userId) {
15
        return $this->find($userId);
16
    }
17
18
    /**
19
     * @param Room  $room
20
     * @param array $onlinePlayerIds
21
     * @param array $excludePlayerIds
22
     * @return User[]
23
     */
24
    public function findOnlineByRoom($room, array $onlinePlayerIds, array $excludePlayerIds = []) {
25
        $builder = $this->createQueryBuilder('u');
26
        $builder->where('u.room = :room');
27
        $builder->andWhere($builder->expr()->in('u.id', $onlinePlayerIds));
28
29
        if (!empty($excludePlayerIds)) {
30
            $builder->andWhere($builder->expr()->notIn('u.id', $excludePlayerIds));
31
        }
32
33
        $builder->setParameters(['room' => $room]);
34
35
        return $builder->getQuery()->getResult();
36
    }
37
38
    /**
39
     * @return User[]
40
     */
41
    public function findAllUsers() {
42
        return $this->findAll();
43
    }
44
45
    /**
46
     * @param string $username
47
     * @return User|null
48
     */
49
    public function findByUsername($username) {
50
        return $this->findOneBy(['username' => $username]);
51
    }
52
53
    /**
54
     * @param string $name
55
     * @return User|null
56
     */
57
    public function findByName($name) {
58
        return $this->findOneBy(['name' => $name]);
59
    }
60
61
    /**
62
     * @param string|int $userNameOrId
63
     * @return User|null
64
     */
65
    public function findByNameOrId($userNameOrId) {
66
        return $this->findByName($userNameOrId) ?: $this->findById($userNameOrId);
67
    }
68
69
    /**
70
     * @param string $email
71
     * @return User|null
72
     */
73
    public function findByEmail($email) {
74
        return $this->findOneBy(['email' => $email]);
75
    }
76
}
77