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
Pull Request — master (#7)
by
unknown
01:28
created

DefaultController::activateUserAction()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 26
Code Lines 18

Duplication

Lines 26
Ratio 100 %

Importance

Changes 0
Metric Value
dl 26
loc 26
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 18
nc 2
nop 4
1
<?php
2
3
namespace Opensoft\RolloutBundle\Controller;
4
5
use Opensoft\RolloutBundle\Rollout\GroupDefinitionAwareRollout;
6
use Opensoft\RolloutBundle\Rollout\UserProviderInterface;
7
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
8
use Symfony\Component\HttpFoundation\RedirectResponse;
9
use Symfony\Component\HttpFoundation\Request;
10
use Symfony\Component\HttpFoundation\Response;
11
12
/**
13
 * @author Richard Fullmer <[email protected]>
14
 */
15
class DefaultController extends Controller
16
{
17
    /**
18
     * @param GroupDefinitionAwareRollout $rollout
19
     *
20
     * @return Response
21
     */
22
    public function indexAction(GroupDefinitionAwareRollout $rollout)
23
    {
24
        return $this->render('OpensoftRolloutBundle:Default:index.html.twig', array('rollout' => $rollout));
25
    }
26
27
    /**
28
     * @param GroupDefinitionAwareRollout $rollout
29
     * @param string $feature
30
     *
31
     * @return RedirectResponse
32
     */
33
    public function activateAction(GroupDefinitionAwareRollout $rollout, string $feature)
34
    {
35
        $rollout->activate($feature);
36
37
        $this->addFlash('success', sprintf("Feature '%s' is now globally activated", $feature));
38
39
        return $this->redirectToRoute('opensoft_rollout');
40
    }
41
42
    /**
43
     * @param GroupDefinitionAwareRollout $rollout
44
     * @param string $feature
45
     *
46
     * @return RedirectResponse
47
     */
48
    public function deactivateAction(GroupDefinitionAwareRollout $rollout, string $feature)
49
    {
50
        $rollout->deactivate($feature);
51
52
        $this->addFlash('danger', sprintf("Feature '%s' is now globally deactivated", $feature));
53
54
        return $this->redirectToRoute('opensoft_rollout');
55
    }
56
57
    /**
58
     * @param GroupDefinitionAwareRollout $rollout
59
     * @param string $feature
60
     *
61
     * @return RedirectResponse
62
     */
63
    public function incrementPercentageAction(GroupDefinitionAwareRollout $rollout, string $feature)
64
    {
65
        return $this->changePercentage($rollout, $feature, 10);
66
    }
67
68
    /**
69
     * @param GroupDefinitionAwareRollout $rollout
70
     * @param string $feature
71
     *
72
     * @return RedirectResponse
73
     */
74
    public function decrementPercentageAction(GroupDefinitionAwareRollout $rollout, string $feature)
75
    {
76
        return $this->changePercentage($rollout, $feature, -10);
77
    }
78
79
    /**
80
     * @param GroupDefinitionAwareRollout $rollout
81
     * @param string $feature
82
     * @param string $group
83
     *
84
     * @return RedirectResponse
85
     */
86
    public function activateGroupAction(GroupDefinitionAwareRollout $rollout, string $feature, string $group)
87
    {
88
        $rollout->activateGroup($feature, $group);
89
90
        $this->addFlash('info', sprintf("Feature '%s' is now active in group '%s'", $feature, $group));
91
92
        return $this->redirectToRoute('opensoft_rollout');
93
    }
94
95
    /**
96
     * @param GroupDefinitionAwareRollout $rollout
97
     * @param string $feature
98
     * @param string $group
99
     *
100
     * @return RedirectResponse
101
     */
102
    public function deactivateGroupAction(GroupDefinitionAwareRollout $rollout, string $feature, string $group)
103
    {
104
        $rollout->deactivateGroup($feature, $group);
105
106
        $this->addFlash('info', sprintf("Feature '%s' is no longer active in group '%s'", $feature, $group));
107
108
        return $this->redirectToRoute('opensoft_rollout');
109
    }
110
111
    /**
112
     * @param Request $request
113
     * @param GroupDefinitionAwareRollout $rollout
114
     * @param UserProviderInterface $userProvider
115
     * @param string $feature
116
     *
117
     * @return RedirectResponse
118
     */
119 View Code Duplication
    public function activateUserAction(
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...
120
        Request $request,
121
        GroupDefinitionAwareRollout $rollout,
122
        UserProviderInterface $userProvider,
123
        string $feature
124
    ) {
125
        $requestUser = $request->get('user');
126
        $user = $userProvider->findByRolloutIdentifier($requestUser);
127
128
        if ($user) {
129
            $rollout->activateUser($feature, $user);
130
131
            $this->addFlash(
132
                'info',
133
                sprintf(
134
                    "User '%s' was activated in feature '%s'",
135
                    $user->getRolloutIdentifier(),
136
                    $feature
137
                )
138
            );
139
        } else {
140
            $this->addFlash('danger', sprintf("User '%s' not found", $requestUser));
141
        }
142
143
        return $this->redirectToRoute('opensoft_rollout');
144
    }
145
146
    /**
147
     * @param GroupDefinitionAwareRollout $rollout
148
     * @param UserProviderInterface $userProvider
149
     * @param string $feature
150
     * @param string $id
151
     *
152
     * @return RedirectResponse
153
     */
154 View Code Duplication
    public function deactivateUserAction(
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...
155
        GroupDefinitionAwareRollout $rollout,
156
        UserProviderInterface $userProvider,
157
        string $feature,
158
        string $id
159
    ) {
160
        $user = $userProvider->findByRolloutIdentifier($id);
161
162
        if ($user) {
163
            $rollout->deactivateUser($feature, $user);
164
165
            $this->addFlash(
166
                'info',
167
                sprintf(
168
                    "User '%s' was deactivated from feature '%s'",
169
                    $user->getRolloutIdentifier(),
170
                    $feature
171
                )
172
            );
173
        } else {
174
            $this->addFlash('danger', sprintf("User '%s' not found", $id));
175
        }
176
177
        return $this->redirectToRoute('opensoft_rollout');
178
    }
179
180
    /**
181
     * @param GroupDefinitionAwareRollout $rollout
182
     * @param string $feature
183
     *
184
     * @return RedirectResponse
185
     */
186
    public function removeAction(GroupDefinitionAwareRollout $rollout, string $feature)
187
    {
188
        $rollout->remove($feature);
189
190
        $this->addFlash('info', sprintf("Feature '%s' was removed from rollout.", $feature));
191
192
        return $this->redirectToRoute('opensoft_rollout');
193
    }
194
195
    /**
196
     * @param Request $request
197
     * @param GroupDefinitionAwareRollout $rollout
198
     * @param string $feature
199
     *
200
     * @return RedirectResponse
201
     */
202
    public function setRequestParamAction(Request $request, GroupDefinitionAwareRollout $rollout, string $feature)
203
    {
204
        $requestParam = $request->get('requestParam');
205
206
        if ($requestParam === null) {
207
            $this->addFlash('danger', 'Missing "requestParam" value');
208
            
209
            return $this->redirectToRoute('opensoft_rollout');
210
        }
211
212
        $rollout->activateRequestParam($feature, $requestParam);
213
214
        $this->addFlash('info', sprintf('Feature "%s" requestParam changed to "%s"', $feature, $requestParam));
215
216
        return $this->redirectToRoute('opensoft_rollout');
217
    }
218
219
    /**
220
     * Abstract out common functionality
221
     *
222
     * @param GroupDefinitionAwareRollout $rollout
223
     * @param string $feature
224
     * @param int $increment
225
     *
226
     * @return RedirectResponse
227
     */
228
    private function changePercentage(GroupDefinitionAwareRollout $rollout, string $feature, int $increment)
229
    {
230
        $percentage = $rollout->get($feature)->getPercentage() + $increment;
231
        $rollout->activatePercentage($feature, $percentage);
232
233
        $this->addFlash('info', sprintf("Feature '%s' percentage changed to %d%% of all users", $feature, $percentage));
234
235
        return $this->redirectToRoute('opensoft_rollout');
236
    }
237
}
238