Completed
Push — master ( 4e360d...80bc96 )
by Daan van
07:27
created

DecodeBase64Transformer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setIdentityProvider() 0 4 1
A transform() 0 14 2
A decodeValue() 0 5 1
1
<?php
2
3
namespace SAML2\Assertion\Transformer;
4
5
use SAML2\Assertion;
6
use SAML2\Configuration\IdentityProvider;
7
use SAML2\Configuration\IdentityProviderAware;
8
9
class DecodeBase64Transformer implements
10
    Transformer,
11
    IdentityProviderAware
12
{
13
    /**
14
     * @var \SAML2\Configuration\IdentityProvider
15
     */
16
    private $identityProvider;
17
18
    public function setIdentityProvider(IdentityProvider $identityProvider)
19
    {
20
        $this->identityProvider = $identityProvider;
21
    }
22
23
    public function transform(Assertion $assertion)
24
    {
25
        if (!$this->identityProvider->hasBase64EncodedAttributes()) {
26
            return $assertion;
27
        }
28
29
        $attributes = $assertion->getAttributes();
30
        $keys = array_keys($attributes);
31
        $decoded = array_map(array($this, 'decodeValue'), $attributes);
32
33
        $attributes = array_combine($keys, $decoded);
34
35
        $assertion->setAttributes($attributes);
36
    }
37
38
    /**
39
     * @param $value
40
     *
41
     * @return array
42
     * @SuppressWarnings(PHPMD.UnusedPrivateMethod)
43
     */
44
    private function decodeValue($value)
45
    {
46
        $elements = explode('_', $value);
47
        return array_map('base64_decode', $elements);
48
    }
49
}
50