FederationMetadata   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 10

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 4
c 4
b 0
f 1
lcom 1
cbo 10
dl 0
loc 54
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A supports() 0 5 1
A manage() 0 16 2
1
<?php
2
3
namespace AerialShip\SamlSPBundle\Bridge;
4
5
use AerialShip\LightSaml\Meta\SerializationContext;
6
use AerialShip\SamlSPBundle\Config\ServiceInfoCollection;
7
use AerialShip\SamlSPBundle\RelyingParty\RelyingPartyInterface;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\HttpFoundation\Response;
10
use Symfony\Component\Security\Http\HttpUtils;
11
12
class FederationMetadata implements RelyingPartyInterface
13
{
14
    /** @var \AerialShip\SamlSPBundle\Config\ServiceInfoCollection */
15
    protected $serviceInfoCollection;
16
17
    /** @var \Symfony\Component\Security\Http\HttpUtils  */
18
    protected $httpUtils;
19
20
21
22
    /**
23
     * @param ServiceInfoCollection $serviceInfoCollection
24
     * @param \Symfony\Component\Security\Http\HttpUtils $httpUtils
25
     */
26
    public function __construct(ServiceInfoCollection $serviceInfoCollection, HttpUtils $httpUtils)
27
    {
28
        $this->serviceInfoCollection = $serviceInfoCollection;
29
        $this->httpUtils = $httpUtils;
30
    }
31
32
33
    /**
34
     * @param \Symfony\Component\HttpFoundation\Request $request
35
     * @return bool
36
     */
37
    function supports(Request $request)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
38
    {
39
        $result = $request->attributes->get('metadata_path') == $request->getPathInfo();
40
        return $result;
41
    }
42
43
44
    /**
45
     * @param \Symfony\Component\HttpFoundation\Request $request
46
     * @throws \Symfony\Component\Process\Exception\RuntimeException
47
     * @return \Symfony\Component\HttpFoundation\Response|SamlSpInfo
48
     */
49
    function manage(Request $request)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
50
    {
51
        $serviceInfo = $this->serviceInfoCollection->findByAS($request->query->get('as'));
52
        if (!$serviceInfo) {
53
            return $this->httpUtils->createRedirectResponse($request, $request->attributes->get('discovery_path').'?type=metadata');
54
        }
55
56
        $serviceInfo->getSpProvider()->setRequest($request);
57
        $ed = $serviceInfo->getSpProvider()->getEntityDescriptor();
58
59
        $context = new SerializationContext();
60
        $ed->getXml($context->getDocument(), $context);
61
        $result = new Response($context->getDocument()->saveXML());
62
        $result->headers->set('Content-Type', 'application/samlmetadata+xml');
63
        return $result;
64
    }
65
}
66