Completed
Push — master ( 5f169a...f49b23 )
by Louis
14s
created

ClubUserRepository   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 65.31 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 3
dl 32
loc 49
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getUserBelowInClubWithPromo() 16 16 1
A getUserAboveInClubWithPromo() 16 16 1
A getCountUsersInClubWithPromo() 0 12 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace KI\UserBundle\Repository;
3
4
use KI\CoreBundle\Repository\ResourceRepository;
5
use KI\UserBundle\Entity\Club;
6
use KI\UserBundle\Entity\User;
7
8
class ClubUserRepository extends ResourceRepository
9
{
10 View Code Duplication
    public function getUserBelowInClubWithPromo(Club $club, $promo, $priority)
11
    {
12
        return $this->getEntityManager()->createQuery('SELECT cu
13
                FROM KIUserBundle:ClubUser cu,
14
                KIUserBundle:User user
15
                WHERE cu.club = :club
16
	            AND cu.user = user
17
                AND user.promo = :promo
18
                AND cu.priority > :priority
19
                ORDER BY cu.priority ASC')
20
        ->setParameter('club', $club)
21
        ->setParameter('priority', $priority)
22
        ->setParameter('promo', $promo)
23
        ->setMaxResults(1)
24
        ->getSingleResult();
25
    }
26
27 View Code Duplication
    public function getUserAboveInClubWithPromo(Club $club, $promo, $priority)
28
    {
29
        return $this->getEntityManager()->createQuery('SELECT cu
30
                FROM KIUserBundle:ClubUser cu,
31
                KIUserBundle:User user
32
                WHERE cu.club = :club
33
	            AND cu.user = user
34
                AND user.promo = :promo
35
                AND cu.priority < :priority
36
                ORDER BY cu.priority DESC')
37
            ->setParameter('club', $club)
38
            ->setParameter('priority', $priority)
39
            ->setParameter('promo', $promo)
40
            ->setMaxResults(1)
41
            ->getSingleResult();
42
    }
43
44
    public function getCountUsersInClubWithPromo(Club $club, $promo)
45
    {
46
        return $this->getEntityManager()->createQuery('SELECT count(cu)
47
                FROM KIUserBundle:ClubUser cu,
48
                KIUserBundle:User user
49
                WHERE cu.club = :club
50
              AND cu.user = user
51
                AND user.promo = :promo')
52
            ->setParameter('club', $club)
53
            ->setParameter('promo', $promo)
54
            ->getSingleScalarResult();
55
    }
56
}
57