Completed
Pull Request — master (#170)
by Simonas
08:55 queued 01:40
created

SettingsController   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 14
Bugs 0 Features 8
Metric Value
wmc 7
c 14
b 0
f 8
lcom 1
cbo 4
dl 0
loc 92
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A listAction() 0 4 1
A updateValueAction() 0 10 1
A deleteAction() 0 19 2
B submitAction() 0 24 3
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\SettingsBundle\Controller;
13
14
use ONGR\ElasticsearchBundle\Result\Aggregation\AggregationValue;
15
use ONGR\ElasticsearchBundle\Service\Repository;
16
use ONGR\ElasticsearchDSL\Aggregation\TermsAggregation;
17
use ONGR\SettingsBundle\Document\Setting;
18
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
19
use Symfony\Component\HttpFoundation\JsonResponse;
20
use Symfony\Component\HttpFoundation\Request;
21
use Symfony\Component\HttpFoundation\Response;
22
23
/**
24
 * Class SettingsListController. Is used for managing settings in General env.
25
 */
26
class SettingsController extends Controller
27
{
28
    /**
29
     * Renders settings list page.
30
     *
31
     * @param Request $request
0 ignored issues
show
Bug introduced by
There is no parameter named $request. 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...
32
     *
33
     * @return Response
34
     */
35
    public function listAction()
36
    {
37
        return $this->render('ONGRSettingsBundle:Settings:list.html.twig');
38
    }
39
40
    /**
41
     * Setting update action.
42
     *
43
     * @param Request $request
44
     *
45
     * @return JsonResponse
46
     */
47
    public function updateValueAction(Request $request)
48
    {
49
        $name = $request->get('name');
50
        $value = $request->get('value');
51
52
        $manager = $this->get('ongr_settings.settings_manager');
53
        $manager->update($name, ['value' => $value]);
54
55
        return new JsonResponse(['error' => false]);
56
    }
57
58
    /**
59
     * Setting delete action
60
     *
61
     * @param Request $request
62
     * @param $id
63
     *
64
     * @return JsonResponse
65
     */
66
    public function deleteAction(Request $request, $id)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
67
    {
68
        try {
69
            /** @var Repository $repo */
70
            $repo = $this->get($this->getParameter('ongr_settings.repo'));
71
72
            $repo->remove($id);
73
74
            return new JsonResponse(['error' => false]);
75
76
        } catch (\Exception $e) {
77
            return new JsonResponse(
78
                [
79
                    'error' => true,
80
                    'message' => 'Error occurred please try to delete setting again.'
81
                ]
82
            );
83
        }
84
    }
85
86
    /**
87
     * Submit action to create or edit setting if not exists.
88
     *
89
     * @param Request $request
90
     *
91
     * @return JsonResponse
92
     */
93
    public function submitAction(Request $request)
94
    {
95
        try {
96
            $manager = $this->get('ongr_settings.settings_manager');
97
            $data = $request->get('setting');
98
99
            if ($request->get('force')) {
100
                $name = $request->get('name');
101
                $manager->update($name, $data);
102
            } else {
103
                $manager->create($data);
104
            }
105
106
            return new JsonResponse(['error' => false]);
107
108
        } catch (\Exception $e) {
109
            return new JsonResponse(
110
                [
111
                    'error' => true,
112
                    'message' => 'Error occurred! Something is wrong with provided data. Please try to submit form again.'
113
                ]
114
            );
115
        }
116
    }
117
}
118