SessionSsoStateStore::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 1
c 2
b 0
f 0
dl 0
loc 3
rs 10
ccs 2
cts 2
cp 1
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace DMK\MKSamlAuth\Store;
4
5
use DMK\MKSamlAuth\Session\PhpSession;
6
use LightSaml\Meta\ParameterBag;
7
use LightSaml\State\Sso\SsoSessionState;
8
use LightSaml\State\Sso\SsoState;
9
use LightSaml\Store\Sso\SsoStateStoreInterface;
10
use TYPO3\CMS\Core\SingletonInterface;
11
12
class SessionSsoStateStore implements SsoStateStoreInterface, SingletonInterface
13
{
14
    private const SESSION_KEY = 'sso_state';
15
16
    /**
17
     * @var PhpSession
18
     */
19
    private $session;
20
21 2
    public function __construct(PhpSession $session)
22
    {
23 2
        $this->session = $session;
24 2
    }
25
26 1
    public function set(SsoState $ssoState)
27
    {
28 1
        $this->session->set(self::SESSION_KEY, serialize($ssoState));
29
30 1
        $ssoState->setLocalSessionId($this->session->getId());
31 1
    }
32
33 2
    public function get()
34
    {
35 2
        $data = $this->session->get(self::SESSION_KEY);
36
37 2
        if (!\is_string($data)) {
38 1
            $state = new SsoState();
39 1
            $this->set($state);
40
41 1
            return $state;
42
        }
43
44 1
        $data = unserialize($data, [
45 1
            'allowed_classes' => [
46
                SsoState::class,
47
                ParameterBag::class,
48
                SsoSessionState::class,
49
            ],
50
        ]);
51
52 1
        if (false === $data) {
53
            $state = new SsoState();
54
            $this->set($state);
55
        }
56
57 1
        return $data;
58
    }
59
}
60