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 |
||
37 | class GatewayController extends Controller |
||
38 | { |
||
39 | const RESPONSE_CONTEXT_SERVICE_ID = 'gateway.proxy.response_context'; |
||
40 | |||
41 | /** |
||
42 | * Receive an AuthnRequest from a service provider. |
||
43 | * |
||
44 | * The service provider is either a Stepup component (SelfService, RA) or |
||
45 | * an external service provider. |
||
46 | * |
||
47 | * This single sign-on action will start a new SAML request to the remote |
||
48 | * IDP configured in Stepup (most likely to be an instance of OpenConext |
||
49 | * EngineBlock). |
||
50 | * |
||
51 | * @param Request $httpRequest |
||
52 | * @return \Symfony\Component\HttpFoundation\RedirectResponse|Response |
||
53 | */ |
||
54 | public function ssoAction(Request $httpRequest) |
||
77 | |||
78 | /** |
||
79 | * |
||
80 | */ |
||
81 | public function proxySsoAction() |
||
85 | |||
86 | /** |
||
87 | * Receive an AuthnResponse from an identity provider. |
||
88 | * |
||
89 | * The AuthnRequest started in ssoAction() resulted in an AuthnResponse |
||
90 | * from the IDP. This method handles the assertion and forwards the user |
||
91 | * using an internal redirect to the SecondFactorController to start the |
||
92 | * actual second factor verification. |
||
93 | * |
||
94 | * @param Request $request |
||
95 | * @return \Symfony\Component\HttpFoundation\Response |
||
96 | */ |
||
97 | public function consumeAssertionAction(Request $request) |
||
112 | |||
113 | /** |
||
114 | * Send a SAML response back to the service provider. |
||
115 | * |
||
116 | * Second factor verification handled by SecondFactorController is |
||
117 | * finished. The user was forwarded back to this action with an internal |
||
118 | * redirect. This method sends a AuthnResponse back to the service |
||
119 | * provider in response to the AuthnRequest received in ssoAction(). |
||
120 | */ |
||
121 | View Code Duplication | public function respondAction() |
|
130 | |||
131 | /** |
||
132 | * @return Response |
||
133 | */ |
||
134 | View Code Duplication | public function sendLoaCannotBeGivenAction() |
|
143 | |||
144 | /** |
||
145 | * @return Response |
||
146 | */ |
||
147 | View Code Duplication | public function sendAuthenticationCancelledByUserAction() |
|
156 | |||
157 | /** |
||
158 | * @param string $view |
||
159 | * @param SAMLResponse $response |
||
160 | * @return Response |
||
161 | */ |
||
162 | View Code Duplication | public function renderSamlResponse($view, SAMLResponse $response) |
|
172 | |||
173 | /** |
||
174 | * @param string $view |
||
175 | * @param array $parameters |
||
176 | * @param Response $response |
||
177 | * @return Response |
||
178 | */ |
||
179 | public function render($view, array $parameters = array(), Response $response = null) |
||
187 | |||
188 | /** |
||
189 | * @return \Surfnet\StepupGateway\GatewayBundle\Saml\ResponseContext |
||
190 | */ |
||
191 | public function getResponseContext() |
||
203 | |||
204 | /** |
||
205 | * @param SAMLResponse $response |
||
206 | * @return string |
||
207 | */ |
||
208 | private function getResponseAsXML(SAMLResponse $response) |
||
212 | |||
213 | /** |
||
214 | * @return SAMLResponse |
||
215 | */ |
||
216 | private function createRequesterFailureResponse() |
||
230 | |||
231 | /** |
||
232 | * @param $context |
||
233 | * @return SAMLResponse |
||
234 | */ |
||
235 | private function createResponseFailureResponse($context) |
||
247 | |||
248 | /** |
||
249 | * @return GatewayLoginService |
||
250 | */ |
||
251 | private function getGatewayLoginService() |
||
255 | |||
256 | } |
||
257 |
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.