Completed
Push — develop ( e7f0df...adc625 )
by Marek
02:45
created

UserRepository::findActiveFollowing()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 10

Duplication

Lines 21
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 21
loc 21
rs 9.3142
cc 1
eloc 10
nc 1
nop 1
1
<?php
2
namespace AppBundle\Entity\Repository;
3
4
use AppBundle\Entity\User;
5
use AppBundle\Entity\UserRelation;
6
use Doctrine\ORM\EntityRepository;
7
8
class UserRepository extends EntityRepository
9
{
10
    /**
11
     * Find all active users followed by user
12
     *
13
     * @param int $userId
14
     *
15
     * @return User[]
16
     */
17 View Code Duplication
    public function findActiveFollowing($userId)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
18
    {
19
        $dql = sprintf(
20
            'SELECT u FROM %s u
21
JOIN %s ur WITH ur.nodeId = u.id
22
WHERE ur.userId = :userId
23
  AND ur.type = :type
24
  AND u.lastAction IS NOT NULL
25
ORDER BY u.login ASC',
26
            User::class,
27
            UserRelation::class
28
        );
29
30
        $query = $this->_em->createQuery($dql)
31
            ->setParameters([
32
                'userId' => $userId,
33
                'type' => UserRelation::TYPE_FRIEND,
34
            ]);
35
36
        return $query->getResult();
37
    }
38
39
    /**
40
     * Find all user's followers
41
     *
42
     * @param int $userId
43
     *
44
     * @return User[]
45
     */
46 View Code Duplication
    public function findAllFollowers($userId)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
47
    {
48
        $dql = sprintf(
49
            'SELECT u FROM %s u
50
JOIN %s ur WITH ur.userId = u.id
51
WHERE ur.nodeId = :userId
52
  AND ur.type = :type
53
ORDER BY u.login ASC',
54
            User::class,
55
            UserRelation::class
56
        );
57
58
        $query = $this->_em->createQuery($dql)
59
            ->setParameters([
60
                'userId' => $userId,
61
                'type' => UserRelation::TYPE_FRIEND,
62
            ]);
63
64
        return $query->getResult();
65
    }
66
67
    /**
68
     * Find all users followed by user
69
     *
70
     * @param int $userId
71
     *
72
     * @return User[]
73
     */
74 View Code Duplication
    public function findAllFollowing($userId)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
    {
76
        $dql = sprintf(
77
            'SELECT u FROM %s u
78
JOIN %s ur WITH ur.nodeId = u.id
79
WHERE ur.userId = :userId
80
  AND ur.type = :type
81
ORDER BY u.login ASC',
82
            User::class,
83
            UserRelation::class
84
        );
85
86
        $query = $this->_em->createQuery($dql)
87
            ->setParameters([
88
                'userId' => $userId,
89
                'type' => UserRelation::TYPE_FRIEND,
90
            ]);
91
92
        return $query->getResult();
93
    }
94
}
95