Completed
Pull Request — feature/acceptance-tests (#191)
by Michiel
02:42 queued 58s
created

ServiceProviderController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A acsAction() 0 22 4
1
<?php
2
3
namespace Surfnet\StepupGateway\Behat\Controller;
4
5
use SAML2\HTTPPost;
6
use SAML2\HTTPRedirect;
7
use SAML2\Response as SAMLResponse;
8
use Surfnet\SamlBundle\Http\XMLResponse;
9
use Symfony\Component\HttpFoundation\Request;
10
11
class ServiceProviderController
12
{
13
    public function __construct()
14
    {
15
    }
16
17
    /**
18
     * Simply dumps the SAMLResponse XML
19
     * @param Request $request
20
     */
21
    public function acsAction(Request $request)
0 ignored issues
show
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...
22
    {
23
        libxml_disable_entity_loader(true);
24
        try {
25
            $httpPostBinding = new HTTPPost();
26
            $message = $httpPostBinding->receive();
27
        } catch (\Exception $e1) {
28
            try {
29
                $httpRedirectBinding = new HTTPRedirect();
30
                $message = $httpRedirectBinding->receive();
31
            } catch (\Exception $e2) {
32
                throw new \RuntimeException('Unable to retrieve SAML message?', 1, $e1);
33
            }
34
        }
35
36
        if (!$message instanceof SAMLResponse) {
37
            throw new \RuntimeException(sprintf('Unrecognized message type received: "%s"', get_class($message)));
38
        }
39
40
        $xml = base64_decode($request->get('SAMLResponse'));
41
        return XMLResponse::create($xml);
42
    }
43
44
}
45