Failed Conditions
Push — issue#764 ( 39afc8 )
by Guilherme
11:43
created

PersonAddressController::getCitiesPrefetchAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace LoginCidadao\APIBundle\Controller;
4
5
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
6
use Symfony\Component\HttpFoundation\Request;
7
use FOS\RestBundle\Controller\Annotations as REST;
8
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
9
use LoginCidadao\APIBundle\Security\Audit\Annotation as Audit;
10
11
/**
12
 * @REST\Prefix("")
13
 */
14
class PersonAddressController extends BaseController
15
{
16
17
    /**
18
     * Searches cities by name and, optionally, state.
19
     *
20
     * @ApiDoc(
21
     *   resource = true,
22
     *   description = "Searches cities by name and, optionally, state.",
23
     *   output = {
24
     *     "class"="LoginCidadao\CoreBundle\Entity\City",
25
     *     "groups" = {"public"}
26
     *   },
27
     *   statusCodes = {
28
     *     200 = "Returned when successful",
29
     *     404 = "Returned when no city is found"
30
     *   }
31
     * )
32
     * @REST\View(templateVar="cities")
33
     * @param string  $city
34
     * @return \LoginCidadao\CoreBundle\Entity\City
35
     * @throws NotFoundHttpException when no city is found
36
     * @REST\Get("/address/cities/search/{city}", defaults={"version": 1})
37
     * @Audit\Loggable(type="SELECT")
38
     */
39
    public function getCitiesAction(Request $request, $city)
40
    {
41
        $countryId = $request->get('country_id', null);
42
        $stateId = $request->get('state_id', null);
43
44
        $em = $this->getDoctrine()->getManager();
45
        $cities = $em->getRepository('LoginCidadaoCoreBundle:City');
46
        $context = $this->getSerializationContext('typeahead');
47
        $result = $cities->findByString($city, $countryId, $stateId);
48
49
        return $this->renderWithContext($result, $context);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->renderWith...text($result, $context) returns the type Symfony\Component\HttpFoundation\Response which is incompatible with the documented return type LoginCidadao\CoreBundle\Entity\City.
Loading history...
50
    }
51
52
    /**
53
     * Searches states by name and, optionally, country.
54
     *
55
     * @ApiDoc(
56
     *   resource = true,
57
     *   description = "Searches states by name and, optionally, country.",
58
     *   output = {
59
     *     "class"="LoginCidadao\CoreBundle\Entity\State",
60
     *     "groups" = {"public"}
61
     *   },
62
     *   statusCodes = {
63
     *     200 = "Returned when successful",
64
     *     404 = "Returned when no city is found"
65
     *   }
66
     * )
67
     * @REST\View(templateVar="states")
68
     * @param string  $state
69
     * @return \LoginCidadao\CoreBundle\Entity\State
70
     * @throws NotFoundHttpException when no state is found
71
     * @REST\Get("/address/states/search/{state}", defaults={"version": 1})
72
     * @Audit\Loggable(type="SELECT")
73
     */
74
    public function getStatesAction($state)
75
    {
76
        $em = $this->getDoctrine()->getManager();
77
        $states = $em->getRepository('LoginCidadaoCoreBundle:State');
78
        $context = $this->getSerializationContext('typeahead');
79
        $result = $states->findByString($state);
80
81
        return $this->renderWithContext($result, $context);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->renderWith...text($result, $context) returns the type Symfony\Component\HttpFoundation\Response which is incompatible with the documented return type LoginCidadao\CoreBundle\Entity\State.
Loading history...
82
    }
83
84
    /**
85
     * Searches countries by name.
86
     *
87
     * @ApiDoc(
88
     *   resource = true,
89
     *   description = "Searches countries by name.",
90
     *   output = {
91
     *     "class"="LoginCidadao\CoreBundle\Entity\Country",
92
     *     "groups" = {"public"}
93
     *   },
94
     *   statusCodes = {
95
     *     200 = "Returned when successful",
96
     *     404 = "Returned when no city is found"
97
     *   }
98
     * )
99
     * @REST\View(templateVar="countries")
100
     * @param string  $country
101
     * @return \LoginCidadao\CoreBundle\Entity\Country
102
     * @throws NotFoundHttpException when no country is found
103
     * @REST\Get("/address/countries/search/{country}", defaults={"version": 1})
104
     * @Audit\Loggable(type="SELECT")
105
     */
106
    public function getCountriesAction($country)
107
    {
108
        $em = $this->getDoctrine()->getManager();
109
        $countries = $em->getRepository('LoginCidadaoCoreBundle:Country');
110
        $context = $this->getSerializationContext('typeahead');
111
        $result = $countries->findByString($country);
112
113
        return $this->renderWithContext($result, $context);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->renderWith...text($result, $context) returns the type Symfony\Component\HttpFoundation\Response which is incompatible with the documented return type LoginCidadao\CoreBundle\Entity\Country.
Loading history...
114
    }
115
116
}
117