SpMetaConfigProvider   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 7
Bugs 0 Features 0
Metric Value
wmc 13
c 7
b 0
f 0
lcom 0
cbo 1
dl 0
loc 80
ccs 46
cts 46
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 24 6
A getSpMeta() 0 4 1
A resolveNameIDFormat() 0 14 3
A resolveBinding() 0 14 3
1
<?php
2
3
namespace AerialShip\SamlSPBundle\Config;
4
5
use AerialShip\LightSaml\Bindings;
6
use AerialShip\LightSaml\Meta\SpMeta;
7
use AerialShip\LightSaml\NameIDPolicy;
8
9
class SpMetaConfigProvider implements SpMetaProviderInterface
10
{
11
    /** @var  SpMeta */
12
    protected $spMeta;
13
14
15 6
    public function __construct(array $config)
16
    {
17 6
        if (!isset($config['name_id_format'])) {
18 4
            $config['name_id_format'] = NameIDPolicy::PERSISTENT;
19 4
        }
20 6
        if (!array_key_exists('binding', $config)) {
21 4
            $config['binding'] = array();
22 4
        }
23 6
        if (!isset($config['binding']['authn_request'])) {
24 4
            $config['binding']['authn_request'] = Bindings::SAML2_HTTP_POST;
25 4
        }
26 6
        if (!isset($config['binding']['response'])) {
27 6
            $config['binding']['response'] = Bindings::SAML2_HTTP_POST;
28 6
        }
29 6
        if (!isset($config['binding']['logout_request'])) {
30 4
            $config['binding']['logout_request'] = Bindings::SAML2_HTTP_POST;
31 4
        }
32
33 6
        $this->spMeta = new SpMeta();
34 6
        $this->spMeta->setNameIdFormat($this->resolveNameIDFormat($config['name_id_format']));
35 6
        $this->spMeta->setAuthnRequestBinding($this->resolveBinding($config['binding']['authn_request']));
36 6
        $this->spMeta->setResponseBinding($this->resolveBinding($config['binding']['response']));
37 6
        $this->spMeta->setLogoutRequestBinding($this->resolveBinding($config['binding']['logout_request']));
38 6
    }
39
40
41
42
    /**
43
     * @return SpMeta
44
     */
45 5
    public function getSpMeta()
46
    {
47 5
        return $this->spMeta;
48
    }
49
50
51
    /**
52
     * @param $value
53
     * @return string
54
     */
55 6
    protected function resolveNameIDFormat($value)
56
    {
57
        switch ($value) {
58 6
            case 'persistent':
59 1
                $result = NameIDPolicy::PERSISTENT;
60 1
                break;
61 5
            case 'transient':
62 1
                $result = NameIDPolicy::TRANSIENT;
63 1
                break;
64 4
            default:
65 4
                $result = $value;
66 4
        }
67 6
        return $result;
68
    }
69
70
    /**
71
     * @param string $value
72
     * @return string
73
     */
74 6
    protected function resolveBinding($value)
75
    {
76
        switch ($value) {
77 6
            case 'post':
78 1
                $result = Bindings::SAML2_HTTP_POST;
79 1
                break;
80 6
            case 'redirect':
81 1
                $result = Bindings::SAML2_HTTP_REDIRECT;
82 1
                break;
83 6
            default:
84 6
                $result = $value;
85 6
        }
86 6
        return $result;
87
    }
88
}
89