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

DecodeBase64Transformer::setIdentityProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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