RelyingPartyCollection::prepend()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
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