SessionSsoStateStore::get()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 25
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3.0416

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 14
c 4
b 0
f 0
dl 0
loc 25
rs 9.7998
ccs 10
cts 12
cp 0.8333
cc 3
nc 3
nop 0
crap 3.0416
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