GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

SettingsController   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 5
dl 0
loc 88
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C indexAction() 0 79 8
1
<?php
2
3
namespace Application\Controller\MembersArea;
4
5
use Application\Form\Type\SettingsType;
6
use Application\Entity\SettingEntity;
7
use Silex\Application;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\HttpFoundation\Response;
10
11
/**
12
 * @author Borut Balažek <[email protected]>
13
 */
14
class SettingsController
15
{
16
    /**
17
     * @param Request     $request
18
     * @param Application $app
19
     *
20
     * @return Response
21
     */
22
    public function indexAction(Request $request, Application $app)
23
    {
24
        if (!$app['security']->isGranted('ROLE_ADMIN')) {
25
            $app->abort(403);
26
        }
27
28
        $form = $app['form.factory']->create(
29
            new SettingsType($app)
30
        );
31
32
        if ($request->getMethod() == 'POST') {
33
            $form->handleRequest($request);
34
35
            if ($form->isValid()) {
36
                $data = $form->getData();
37
38
                if (!empty($data)) {
39
                    foreach ($data as $key => $value) {
40
                        $settingEntity = $app['orm.em']
41
                            ->getRepository('Application\Entity\SettingEntity')
42
                            ->findOneByKey($key)
43
                        ;
44
45
                        if ($settingEntity === null) {
46
                            $settingEntity = new SettingEntity();
47
48
                            $settingEntity
49
                                ->setKey($key)
50
                            ;
51
                        }
52
53
                        $settingEntity
54
                            ->setValue($value)
55
                        ;
56
57
                        $app['orm.em']->persist($settingEntity);
58
                    }
59
60
                    try {
61
                        $app['orm.em']->flush();
62
63
                        $app['flashbag']->add(
64
                            'success',
65
                            $app['translator']->trans(
66
                                'The settings were successfully saved!'
67
                            )
68
                        );
69
                    } catch (\Exception $e) {
70
                        $app['flashbag']->add(
71
                            'danger',
72
                            $e->getMessage()
73
                        );
74
                    }
75
76
                    return $app->redirect(
77
                        $app['url_generator']->generate(
78
                            'members-area.settings'
79
                        )
80
                    );
81
                } else {
82
                    $app['flashbag']->add(
83
                        'info',
84
                        $app['translator']->trans(
85
                            'No changes were saved!'
86
                        )
87
                    );
88
                }
89
            }
90
        }
91
92
        return new Response(
93
            $app['twig']->render(
94
                'contents/members-area/settings/index.html.twig',
95
                array(
96
                    'form' => $form->createView(),
97
                )
98
            )
99
        );
100
    }
101
}
102