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.
Completed
Push — develop ( f4db36...17d5e7 )
by Borut
04:02
created

MyController::settingsAction()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 50
Code Lines 27

Duplication

Lines 28
Ratio 56 %

Importance

Changes 3
Bugs 2 Features 0
Metric Value
c 3
b 2
f 0
dl 28
loc 50
rs 9.3333
cc 3
eloc 27
nc 3
nop 2
1
<?php
2
3
namespace Application\Controller\MembersArea;
4
5
use Silex\Application;
6
use Symfony\Component\HttpFoundation\Request;
7
use Symfony\Component\HttpFoundation\Response;
8
use Application\Form\Type\User\SettingsType;
9
use Application\Form\Type\User\PasswordType;
10
11
/**
12
 * @author Borut Balažek <[email protected]>
13
 */
14
class MyController
15
{
16
    /**
17
     * @param Application $app
18
     *
19
     * @return Response
20
     */
21
    public function indexAction(Application $app)
22
    {
23
        return $app->redirect(
24
            $app['url_generator']->generate('members-area.my.profile')
25
        );
26
    }
27
28
    /**
29
     * @param Application $app
30
     *
31
     * @return Response
32
     */
33
    public function profileAction(Application $app)
34
    {
35
        return new Response(
36
            $app['twig']->render(
37
                'contents/members-area/my/profile.html.twig'
38
            )
39
        );
40
    }
41
42
    /**
43
     * @param Request     $request
44
     * @param Application $app
45
     *
46
     * @return Response
47
     */
48
    public function settingsAction(Request $request, Application $app)
49
    {
50
        $data = array();
51
52
        $form = $app['form.factory']->create(
53
            new SettingsType(),
54
            $app['user']
55
        );
56
57
        // Security fix
58
        $currentUserUsername = $app['user']->getUsername();
59
60 View Code Duplication
        if ($request->getMethod() == 'POST') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
61
            $form->handleRequest($request);
62
           
63
            // Security fix
64
            $app['user']->setUsername($currentUserUsername);
65
66
            if ($form->isValid()) {
67
                $userEntity = $form->getData();
68
69
                /*** Image ***/
70
                $userEntity
71
                    ->getProfile()
72
                    ->setImageUploadPath($app['baseUrl'].'/assets/uploads/')
73
                    ->setImageUploadDir(WEB_DIR.'/assets/uploads/')
74
                    ->imageUpload()
75
                ;
76
77
                $app['orm.em']->persist($userEntity);
78
                $app['orm.em']->flush();
79
80
                $app['flashbag']->add(
81
                    'success',
82
                    $app['translator']->trans(
83
                        'Your settings were successfully saved!'
84
                    )
85
                );
86
            }
87
        }
88
89
        $data['form'] = $form->createView();
90
91
        return new Response(
92
            $app['twig']->render(
93
                'contents/members-area/my/settings.html.twig',
94
                $data
95
            )
96
        );
97
    }
98
99
    /**
100
     * @param Request     $request
101
     * @param Application $app
102
     *
103
     * @return Response
104
     */
105
    public function passwordAction(Request $request, Application $app)
106
    {
107
        $data = array();
108
109
        $form = $app['form.factory']->create(
110
            new PasswordType(),
111
            $app['user']
112
        );
113
114
        if ($request->getMethod() == 'POST') {
115
            $form->handleRequest($request);
116
117
            if ($form->isValid()) {
118
                $userEntity = $form->getData();
119
120
                if ($userEntity->getPlainPassword()) {
121
                    $userEntity->setPlainPassword(
122
                        $userEntity->getPlainPassword(),
123
                        $app['security.encoder_factory']
124
                    );
125
126
                    $app['orm.em']->persist($userEntity);
127
                    $app['orm.em']->flush();
128
129
                    $app['flashbag']->add(
130
                        'success',
131
                        $app['translator']->trans(
132
                            'Your password was successfully changed!'
133
                        )
134
                    );
135
                }
136
            }
137
        }
138
139
        $data['form'] = $form->createView();
140
141
        return new Response(
142
            $app['twig']->render(
143
                'contents/members-area/my/password.html.twig',
144
                $data
145
            )
146
        );
147
    }
148
}
149