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:43
created

DefaultController   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 209
Duplicated Lines 16.27 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 6
dl 34
loc 209
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A indexAction() 0 4 1
A activateAction() 0 8 1
A deactivateAction() 0 8 1
A incrementPercentageAction() 9 9 1
A decrementPercentageAction() 9 9 1
A activateGroupAction() 8 8 1
A deactivateGroupAction() 8 8 1
B activateUserAction() 0 26 2
A deactivateUserAction() 0 20 1
A removeAction() 0 8 1
A setRequestParamAction() 0 16 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Opensoft\RolloutBundle\Controller;
4
5
use Opensoft\Rollout\Rollout;
6
use Opensoft\RolloutBundle\Rollout\GroupDefinitionAwareRollout;
7
use Opensoft\RolloutBundle\Rollout\UserProviderInterface;
8
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
9
use Symfony\Component\HttpFoundation\RedirectResponse;
10
use Symfony\Component\HttpFoundation\Request;
11
use Symfony\Component\HttpFoundation\Response;
12
13
/**
14
 * @author Richard Fullmer <[email protected]>
15
 */
16
class DefaultController extends Controller
17
{
18
    /**
19
     * @param GroupDefinitionAwareRollout $rollout
20
     *
21
     * @return Response
22
     */
23
    public function indexAction(GroupDefinitionAwareRollout $rollout)
24
    {
25
        return $this->render('OpensoftRolloutBundle:Default:index.html.twig', array('rollout' => $rollout));
26
    }
27
28
    /**
29
     * @param GroupDefinitionAwareRollout $rollout
30
     * @param string $feature
31
     *
32
     * @return RedirectResponse
33
     */
34
    public function activateAction(GroupDefinitionAwareRollout $rollout, string $feature)
35
    {
36
        $rollout->activate($feature);
37
38
        $this->addFlash('success', sprintf("Feature '%s' is now globally activated", $feature));
39
40
        return $this->redirectToRoute('opensoft_rollout');
41
    }
42
43
    /**
44
     * @param GroupDefinitionAwareRollout $rollout
45
     * @param string $feature
46
     *
47
     * @return RedirectResponse
48
     */
49
    public function deactivateAction(GroupDefinitionAwareRollout $rollout, string $feature)
50
    {
51
        $rollout->deactivate($feature);
52
53
        $this->addFlash('danger', sprintf("Feature '%s' is now globally deactivated", $feature));
54
55
        return $this->redirectToRoute('opensoft_rollout');
56
    }
57
58
    /**
59
     * @param GroupDefinitionAwareRollout $rollout
60
     * @param string $feature
61
     *
62
     * @return RedirectResponse
63
     */
64 View Code Duplication
    public function incrementPercentageAction(GroupDefinitionAwareRollout $rollout, string $feature)
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...
65
    {
66
        $percentage = $rollout->get($feature)->getPercentage() + 10;
67
        $rollout->activatePercentage($feature, $percentage);
68
69
        $this->addFlash('info', sprintf("Feature '%s' percentage changed to %d%% of all users", $feature, $percentage));
70
71
        return $this->redirectToRoute('opensoft_rollout');
72
    }
73
74
    /**
75
     * @param GroupDefinitionAwareRollout $rollout
76
     * @param string $feature
77
     *
78
     * @return RedirectResponse
79
     */
80 View Code Duplication
    public function decrementPercentageAction(GroupDefinitionAwareRollout $rollout, string $feature)
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...
81
    {
82
        $percentage = $rollout->get($feature)->getPercentage() - 10;
83
        $rollout->activatePercentage($feature, $percentage);
84
85
        $this->addFlash('info', sprintf("Feature '%s' percentage changed to %d%% of all users", $feature, $percentage));
86
87
        return $this->redirectToRoute('opensoft_rollout');
88
    }
89
90
    /**
91
     * @param GroupDefinitionAwareRollout $rollout
92
     * @param string $feature
93
     * @param string $group
94
     *
95
     * @return RedirectResponse
96
     */
97 View Code Duplication
    public function activateGroupAction(GroupDefinitionAwareRollout $rollout, string $feature, string $group)
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...
98
    {
99
        $rollout->activateGroup($feature, $group);
100
101
        $this->addFlash('info', sprintf("Feature '%s' is now active in group '%s'", $feature, $group));
102
103
        return $this->redirectToRoute('opensoft_rollout');
104
    }
105
106
    /**
107
     * @param GroupDefinitionAwareRollout $rollout
108
     * @param string $feature
109
     * @param string $group
110
     *
111
     * @return RedirectResponse
112
     */
113 View Code Duplication
    public function deactivateGroupAction(GroupDefinitionAwareRollout $rollout, string $feature, string $group)
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...
114
    {
115
        $rollout->deactivateGroup($feature, $group);
116
117
        $this->addFlash('info', sprintf("Feature '%s' is no longer active in group '%s'", $feature, $group));
118
119
        return $this->redirectToRoute('opensoft_rollout');
120
    }
121
122
    /**
123
     * @param Request $request
124
     * @param GroupDefinitionAwareRollout $rollout
125
     * @param UserProviderInterface $userProvider
126
     * @param string $feature
127
     *
128
     * @return RedirectResponse
129
     */
130
    public function activateUserAction(
131
        Request $request,
132
        GroupDefinitionAwareRollout $rollout,
133
        UserProviderInterface $userProvider,
134
        string $feature
135
    ) {
136
        $requestUser = $request->get('user');
137
        $user = $userProvider->findByRolloutIdentifier($requestUser);
138
139
        if ($user) {
140
            $rollout->activateUser($feature, $user);
141
142
            $this->addFlash(
143
                'info',
144
                sprintf(
145
                    "User '%s' was activated in feature '%s'",
146
                    $user->getRolloutIdentifier(),
147
                    $feature
148
                )
149
            );
150
        } else {
151
            $this->addFlash('danger', sprintf("User '%s' not found", $requestUser));
152
        }
153
154
        return $this->redirectToRoute('opensoft_rollout');
155
    }
156
157
    /**
158
     * @param GroupDefinitionAwareRollout $rollout
159
     * @param UserProviderInterface $userProvider
160
     * @param string $feature
161
     * @param string $id
162
     *
163
     * @return RedirectResponse
164
     */
165
    public function deactivateUserAction(
166
        GroupDefinitionAwareRollout $rollout,
167
        UserProviderInterface $userProvider,
168
        string $feature,
169
        string $id
170
    ) {
171
        $user = $userProvider->findByRolloutIdentifier($id);
172
        $rollout->deactivateUser($feature, $user);
0 ignored issues
show
Bug introduced by
It seems like $user defined by $userProvider->findByRolloutIdentifier($id) on line 171 can be null; however, Opensoft\Rollout\Rollout::deactivateUser() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
173
174
        $this->addFlash(
175
            'info',
176
            sprintf(
177
                "User '%s' was deactivated from feature '%s'",
178
                $user->getRolloutIdentifier(),
179
                $feature
180
            )
181
        );
182
183
        return $this->redirectToRoute('opensoft_rollout');
184
    }
185
186
    /**
187
     * @param GroupDefinitionAwareRollout $rollout
188
     * @param string $feature
189
     *
190
     * @return RedirectResponse
191
     */
192
    public function removeAction(GroupDefinitionAwareRollout $rollout, string $feature)
193
    {
194
        $rollout->remove($feature);
195
196
        $this->addFlash('info', sprintf("Feature '%s' was removed from rollout.", $feature));
197
198
        return $this->redirectToRoute('opensoft_rollout');
199
    }
200
201
    /**
202
     * @param Request $request
203
     * @param GroupDefinitionAwareRollout $rollout
204
     * @param string $feature
205
     *
206
     * @return RedirectResponse
207
     */
208
    public function setRequestParamAction(Request $request, GroupDefinitionAwareRollout $rollout, string $feature)
209
    {
210
        $requestParam = $request->get('requestParam');
211
212
        if ($requestParam === null) {
213
            $this->addFlash('danger', 'Missing "requestParam" value');
214
            
215
            return $this->redirectToRoute('opensoft_rollout');
216
        }
217
218
        $rollout->activateRequestParam($feature, $requestParam);
219
220
        $this->addFlash('info', sprintf('Feature "%s" requestParam changed to "%s"', $feature, $requestParam));
221
222
        return $this->redirectToRoute('opensoft_rollout');
223
    }
224
}
225