RelyingPartyCollection   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 8
c 3
b 0
f 0
lcom 1
cbo 1
dl 0
loc 54
ccs 18
cts 18
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A append() 0 4 1
A prepend() 0 4 1
A supports() 0 4 1
A manage() 0 7 2
A findRelyingPartySupportedRequest() 0 9 3
1
<?php
2
3
namespace AerialShip\SamlSPBundle\RelyingParty;
4
5
use Symfony\Component\HttpFoundation\Request;
6
7
class RelyingPartyCollection implements RelyingPartyInterface
8
{
9
    /** @var RelyingPartyInterface[] */
10
    protected $relyingParties = array();
11
12
    /**
13
     * @param RelyingPartyInterface $relyingParty
14
     */
15 7
    public function append(RelyingPartyInterface $relyingParty)
16
    {
17 7
        array_push($this->relyingParties, $relyingParty);
18 7
    }
19
20
    /**
21
     * @param RelyingPartyInterface $relyingParty
22
     */
23 2
    public function prepend(RelyingPartyInterface $relyingParty)
24
    {
25 2
        array_unshift($this->relyingParties, $relyingParty);
26 2
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 6
    public function supports(Request $request)
32
    {
33 6
        return (bool) $this->findRelyingPartySupportedRequest($request);
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 4
    public function manage(Request $request)
40
    {
41 4
        if (false == $relyingParty = $this->findRelyingPartySupportedRequest($request)) {
42 2
            throw new \InvalidArgumentException('The relying party does not support the request');
43
        }
44 2
        return $relyingParty->manage($request);
45
    }
46
47
    /**
48
     * @param \Symfony\Component\HttpFoundation\Request $request
49
     * @return RelyingPartyInterface|null
50
     */
51 8
    protected function findRelyingPartySupportedRequest(Request $request)
52
    {
53 8
        foreach ($this->relyingParties as $relyingParty) {
54 6
            if ($relyingParty->supports($request)) {
55 4
                return $relyingParty;
56
            }
57 5
        }
58 4
        return null;
59
    }
60
}
61