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 — master ( 23c71a...dcb9a9 )
by Richard
11:04
created

ManagementController::settingsAction()   D

Complexity

Conditions 18
Paths 144

Size

Total Lines 136
Code Lines 74

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 136
c 0
b 0
f 0
rs 4.5072
cc 18
eloc 74
nc 144
nop 1

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: wechsler
5
 * Date: 28/01/2017
6
 * Time: 19:12
7
 */
8
9
namespace Phase\TakeATicketBundle\Controller;
10
11
use Phase\TakeATicket\SongLoader;
12
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
13
use Symfony\Component\Form\Extension\Core\Type\FileType;
14
use Symfony\Component\Form\Extension\Core\Type\FormType;
15
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
16
use Symfony\Component\Form\Extension\Core\Type\TextType;
17
use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationExtension;
18
use Symfony\Component\Form\Forms;
19
use Symfony\Component\HttpFoundation\File\UploadedFile;
20
use Symfony\Component\HttpFoundation\Request;
21
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
22
23
class ManagementController extends BaseController
24
{
25
    public function indexAction()
26
    {
27
        $this->denyAccessUnlessGranted('ROLE_ADMIN');
28
29
        $tickets = $this->getDataStore()->fetchUndeletedTickets();
30
31
        $performers = $this->getDataStore()->generatePerformerStats();
32
33
        return $this->render(
34
            'default/manage.html.twig',
35
            [
36
                'tickets' => $tickets,
37
                'performers' => $performers,
38
                'displayOptions' => $this->getDisplayOptions(),
39
            ]
40
        );
41
    }
42
43
44 View Code Duplication
    public function helpAction($section = 'readme')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
45
    {
46
        $this->denyAccessUnlessGranted('ROLE_ADMIN');
47
48
        $rootDir = realpath(__DIR__ . '/../../../../');
49
        $map = [
50
            'readme' => $rootDir . '/README.md',
51
            'CONTRIBUTING' => $rootDir . '/docs/CONTRIBUTING.md',
52
            'TODO' => $rootDir . '/docs/TODO.md',
53
        ];
54
55
        if (!isset($map[$section])) {
56
            throw new NotFoundHttpException();
57
        }
58
59
        $markdown = file_get_contents($map[$section]);
60
61
        $markdown = preg_replace(
62
            '#\[docs/\w+.md\]\((./)?docs/(\w+).md\)#',
63
            '[docs/$2.md](/help/$2)',
64
            $markdown
65
        );
66
67
        return $this->render(
68
            ':default:help.html.twig',
69
            ['helpText' => $markdown]
70
        );
71
    }
72
73
    public function settingsAction(Request $request)
74
    {
75
        $this->denyAccessUnlessGranted('ROLE_ADMIN');
76
77
        $requiredResetText = 'THIS DELETES ALL TICKETS';
78
79
        $settingKeys = [
80
            'freeze' => false,
81
            'freezeMessage' => '',
82
            'remotesUrl' => '/'
83
        ];
84
85
        $formDefaults = $settingKeys;
86
87
        foreach ($settingKeys as $k => $v) {
88
            $value = $this->getDataStore()->getSetting($k);
89
            if (!is_null($value)) {
90
                $formDefaults[$k] = is_bool($v) ? (bool)$value : $value; // fixme handle type better
91
            }
92
        }
93
94
        $formFactory = Forms::createFormFactoryBuilder()
95
            ->addExtension(new HttpFoundationExtension())
96
            ->getFormFactory();
97
98
        $settingsSubmit = 'Save Settings';
99
        $settingsForm = $formFactory->createNamedBuilder('settingsForm', FormType::class, $formDefaults)
100
            ->add('freeze', CheckboxType::class, ['label' => 'Display "Queue Frozen" message'])
101
            ->add('freezeMessage', TextType::class, ['label' => 'Customise "Queue Frozen" message'])
102
            ->add('remotesUrl', TextType::class, ['label' => 'URL to display on remote screens'])
103
            ->add($settingsSubmit, SubmitType::class)
104
            ->getForm();
105
106
        $settingsFormSaved = false;
107
108
        if ($request->request->has('settingsForm')) {
109
            $settingsForm->handleRequest($request);
110
111
            /**
112
 * @noinspection PhpUndefinedMethodInspection
113
*/ // isClicked on Submit
114
            if ($settingsForm->isSubmitted()
115
                && $settingsForm->isValid()
116
                && $settingsForm->get($settingsSubmit)->isClicked()
117
            ) {
118
                $data = $settingsForm->getData();
119
                foreach ($data as $k => $v) {
120
                    $this->getDataStore()->updateSetting($k, $v);
121
                }
122
                $settingsFormSaved = true;
123
            }
124
        }
125
126
        // ----------------
127
128
        $resetSubmit = 'Reset all';
129
        $resetForm = $formFactory->createNamedBuilder('resetForm', FormType::class, $formDefaults)
130
            ->add('resetMessage', TextType::class)
131
            ->add($resetSubmit, SubmitType::class)
132
            ->getForm();
133
134
135
        $resetFormSaved = false;
136
137
        if ($request->request->has('resetForm')) {
138
            $resetForm->handleRequest($request);
139
140
            /**
141
 * @noinspection PhpUndefinedMethodInspection
142
*/ // isClicked on Submit
143
            if ($resetForm->isSubmitted()
144
                && $resetForm->isValid()
145
                && $resetForm->get($resetSubmit)->isClicked()
146
            ) {
147
                $data = $resetForm->getData();
148
                //                var_dump($data);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
149
                //                die();
150
                if (trim($data['resetMessage']) === $requiredResetText) {
151
                    $this->getDataStore()->resetAllSessionData();
152
                    $resetFormSaved = true;
153
                }
154
            }
155
        }
156
157
        // -------------------
158
159
        $songListSubmit = 'Upload song list';
160
        $songListForm = $formFactory->createNamedBuilder('songListForm', FormType::class, $formDefaults)
161
            ->add('songListFile', FileType::class)
162
            ->add($songListSubmit, SubmitType::class)
163
            ->getForm();
164
165
        $songFormSaved = false;
166
        $songsLoaded = false;
167
168
        if ($request->request->has('songListForm')) {
169
            $songListForm->handleRequest($request);
170
171
            /**
172
 * @noinspection PhpUndefinedMethodInspection
173
*/ // isClicked on Submit
174
            if ($songListForm->isSubmitted()
175
                && $songListForm->isValid()
176
                && $songListForm->get($songListSubmit)->isClicked()
177
            ) {
178
                $data = $songListForm->getData();
179
180
                $file = $data['songListFile'];
181
                /**
182
 * @var UploadedFile $file
183
*/
184
185
                $loader = new SongLoader();
186
187
                $songsLoaded = $loader->run($file->getPathname(), $this->get('database_connection'));
188
189
                $songFormSaved = true;
190
            }
191
        }
192
193
        // -------------------
194
195
        return $this->render(
196
            ':admin:settings.html.twig',
197
            [
198
                'settingsFormSaved' => $settingsFormSaved,
199
                'settingsForm' => $settingsForm->createView(),
200
                'resetForm' => $resetForm->createView(),
201
                'resetFormSaved' => $resetFormSaved,
202
                'resetRequiredText' => $requiredResetText,
203
                'songListForm' => $songListForm->createView(),
204
                'songFormSaved' => $songFormSaved,
205
                'songsLoaded' => $songsLoaded,
206
            ]
207
        );
208
    }
209
}
210