Completed
Pull Request — develop (#91)
by Boy
03:03
created

FailureController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 66
Duplicated Lines 93.94 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 2
c 3
b 0
f 0
lcom 0
cbo 5
dl 62
loc 66
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B sendLoaCannotBeGivenAction() 29 29 1
B sendAuthenticationCancelledByUserAction() 33 33 1

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
/**
4
 * Copyright 2014 SURFnet bv
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace Surfnet\StepupGateway\GatewayBundle\Controller;
20
21
use SAML2_Const;
22
use Surfnet\StepupGateway\GatewayBundle\Saml\ResponseContext;
23
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
24
25
class FailureController extends Controller
26
{
27 View Code Duplication
    public function sendLoaCannotBeGivenAction()
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...
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
28
    {
29
        /** @var ResponseContext $responseContext */
30
        $responseContext = $this->get(
31
          $this->get('gateway.proxy.state_handler')->getResponseContextServiceId()
32
        );
33
        $originalRequestId = $responseContext->getInResponseTo();
34
35
        /** @var \Surfnet\SamlBundle\Monolog\SamlAuthenticationLogger $logger */
36
        $logger = $this->get('surfnet_saml.logger')->forAuthentication($originalRequestId);
37
        $logger->notice('Loa cannot be given, creating Response with NoAuthnContext status');
38
39
        /** @var \Surfnet\StepupGateway\GatewayBundle\Saml\ResponseBuilder $responseBuilder */
40
        $responseBuilder = $this->get('gateway.proxy.response_builder');
41
42
        $response = $responseBuilder
43
          ->createNewResponse($responseContext)
44
          ->setResponseStatus(SAML2_Const::STATUS_RESPONDER, SAML2_Const::STATUS_NO_AUTHN_CONTEXT)
45
          ->get();
46
47
        $logger->notice(sprintf(
48
          'Responding to request "%s" with response based on response from the remote IdP with response "%s"',
49
          $responseContext->getInResponseTo(),
50
          $response->getId()
51
        ));
52
53
        $responseRendering = $this->get('gateway.service.saml_response');
54
        return $responseRendering->renderResponse($responseContext, $response);
55
    }
56
57 View Code Duplication
    public function sendAuthenticationCancelledByUserAction()
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...
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
58
    {
59
        /** @var ResponseContext $responseContext */
60
        $responseContext = $this->get(
61
          $this->get('gateway.proxy.state_handler')->getResponseContextServiceId()
62
        );
63
        $originalRequestId = $responseContext->getInResponseTo();
64
65
        /** @var \Surfnet\SamlBundle\Monolog\SamlAuthenticationLogger $logger */
66
        $logger = $this->get('surfnet_saml.logger')->forAuthentication($originalRequestId);
67
        $logger->notice('Authentication was cancelled by the user, creating Response with AuthnFailed status');
68
69
        /** @var \Surfnet\StepupGateway\GatewayBundle\Saml\ResponseBuilder $responseBuilder */
70
        $responseBuilder = $this->get('gateway.proxy.response_builder');
71
72
        $response = $responseBuilder
73
          ->createNewResponse($responseContext)
74
          ->setResponseStatus(
75
            SAML2_Const::STATUS_RESPONDER,
76
            SAML2_Const::STATUS_AUTHN_FAILED,
77
            'Authentication cancelled by user'
78
          )
79
          ->get();
80
81
        $logger->notice(sprintf(
82
          'Responding to request "%s" with response based on response from the remote IdP with response "%s"',
83
          $responseContext->getInResponseTo(),
84
          $response->getId()
85
        ));
86
87
        $responseRendering = $this->get('gateway.service.saml_response');
88
        return $responseRendering->renderResponse($responseContext, $response);
89
    }
90
}
91