Completed
Push — master ( a8e426...cdcd92 )
by Simonas
62:46
created

ManagerController::jsonAction()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
nop 2
1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ONGR\FilterManagerBundle\Controller;
13
14
use ONGR\FilterManagerBundle\DependencyInjection\ONGRFilterManagerExtension;
15
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
16
use Symfony\Component\HttpFoundation\JsonResponse;
17
use Symfony\Component\HttpFoundation\Request;
18
use Symfony\Component\HttpFoundation\Response;
19
20
/**
21
 * Class ManagerController.
22
 */
23
class ManagerController extends Controller
24
{
25
    /**
26
     * Renders view with filter manager response.
27
     *
28
     * @param Request $request     Request.
29
     * @param string  $managerName Filter manager name.
30
     * @param string  $template    Template name.
31
     *
32
     * @return Response
33
     */
34
    public function managerAction(Request $request, $managerName, $template)
35
    {
36
        return $this->render(
37
            $template,
38
            $this->getFilterManagerResponse($request, $managerName)
39
        );
40
    }
41
42
    /**
43
     * Returns search response results from filter manager.
44
     *
45
     * @param Request $request Request.
46
     * @param string  $managerName    Filter manager name.
47
     *
48
     * @return array
49
     */
50
    protected function getFilterManagerResponse(Request $request, $managerName)
51
    {
52
        return [
53
            'filter_manager' => $this->get(ONGRFilterManagerExtension::getFilterManagerId($managerName))
54
                ->handleRequest($request)
55
        ];
56
    }
57
58
    /**
59
     * Returns JSON response with search response data.
60
     *
61
     * @param Request $request Request.
62
     * @param string  $name    Filter manager name.
0 ignored issues
show
Bug introduced by
There is no parameter named $name. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
63
     *
64
     * @return JsonResponse
65
     */
66
    public function jsonAction(Request $request, $managerName)
67
    {
68
        $data = $this->get(ONGRFilterManagerExtension::getFilterManagerId($managerName))
69
            ->handleRequest($request)
70
            ->getSerializableData();
71
72
        $response = new JsonResponse($data);
73
74
        if ($request->query->has('pretty')) {
75
            $response->setEncodingOptions(JSON_PRETTY_PRINT);
76
        }
77
78
        return $response;
79
    }
80
}
81