Completed
Push — master ( 91da94...ed2312 )
by Lucas
05:02 queued 11s
created

CityRepository::countCities()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 1
b 0
f 0
1
<?php
2
3
namespace LoginCidadao\CoreBundle\Entity;
4
5
use Doctrine\ORM\EntityRepository;
6
7
class CityRepository extends EntityRepository
8
{
9
10
    public function findByString($string, $countryId = null, $stateId = null)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
11
    {
12
        $qb = $this->getEntityManager()->createQueryBuilder();
13
14
        $qb
15
            ->select('c')
16
            ->from('LoginCidadaoCoreBundle:City', 'c')
17
            ->join(
18
                'LoginCidadaoCoreBundle:State',
19
                's',
20
                'WITH',
21
                'c.state = s'
22
            )
23
            ->join(
24
                'LoginCidadaoCoreBundle:Country',
25
                'co',
26
                'WITH',
27
                's.country = co'
28
            )
29
            ->where('c.name LIKE :string OR LOWER(c.name) LIKE :string')
30
            ->addOrderBy('s.preference', 'DESC')
31
            ->addOrderBy('c.name', 'ASC')
32
            ->setParameter('string', "$string%");
33
34
        if ($stateId > 0) {
35
            $qb->andWhere('s.id = :stateId')
36
                ->setParameter('stateId', $stateId);
37
        }
38
        if ($countryId > 0) {
39
            $qb->andWhere('co.id = :countryId')
40
                ->setParameter('countryId', $countryId);
41
        }
42
43
        return $qb->getQuery()->getResult();
44
    }
45
46
    public function findByPreferedState()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
47
    {
48
        $em = $this->getEntityManager();
49
        $states = $em->getRepository('LoginCidadaoCoreBundle:State')
50
            ->createQueryBuilder('s')
51
            ->orderBy('s.preference', 'DESC')
52
            ->setMaxResults(1)
53
            ->getQuery()->getResult();
54
        $state = reset($states);
55
        $cities = $state->getCities();
56
57
        return $cities;
58
    }
59
60
    /**
61
     * @return mixed
62
     */
63
    public function countCities()
64
    {
65
        return $this->createQueryBuilder('c')
66
            ->select('COUNT(c)')
67
            ->getQuery()->getSingleScalarResult();
68
    }
69
}
70