StateHandler   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 63
rs 10
c 0
b 0
f 0
wmc 12

10 Methods

Rating   Name   Duplication   Size   Complexity  
A setRequestId() 0 5 1
A __construct() 0 3 1
A get() 0 3 1
A set() 0 3 1
A getAuthMethod() 0 3 1
A getRequestId() 0 3 1
A setAuthMethod() 0 5 1
A hasMatchingRequestId() 0 8 3
A setContext() 0 5 1
A getContext() 0 3 1
1
<?php
2
3
/**
4
 * Copyright 2017 SURFnet bv
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace Surfnet\StepupGateway\SecondFactorOnlyBundle\Adfs;
20
21
use Symfony\Component\HttpFoundation\RequestStack;
22
23
class StateHandler
24
{
25
    public const SESSION_PATH = 'surfnet/gateway/adfs';
26
27
    public function __construct(
28
        private RequestStack $requestStack,
29
    ) {
30
    }
31
32
    public function setRequestId(string $originalRequestId): StateHandler
33
    {
34
        $this->set('request_id', $originalRequestId);
35
36
        return $this;
37
    }
38
39
    public function setAuthMethod(string $authMethod): StateHandler
40
    {
41
        $this->set('auth_method', $authMethod);
42
43
        return $this;
44
    }
45
46
    public function setContext(string $context): StateHandler
47
    {
48
        $this->set('context', $context);
49
50
        return $this;
51
    }
52
53
    public function getRequestId(): mixed
54
    {
55
        return $this->get('request_id');
56
    }
57
58
    public function getAuthMethod(): mixed
59
    {
60
        return $this->get('auth_method');
61
    }
62
63
    public function getContext(): mixed
64
    {
65
        return $this->get('context');
66
    }
67
68
    public function hasMatchingRequestId(?string $requestId): bool
69
    {
70
        $requestIdFromSession = $this->get('request_id');
71
        if ($requestIdFromSession && $requestIdFromSession == $requestId) {
72
            return true;
73
        }
74
75
        return false;
76
    }
77
78
    protected function set(string $key, mixed $value): void
79
    {
80
        $this->requestStack->getSession()->set(self::SESSION_PATH . $key, $value);
81
    }
82
83
    protected function get(string $key): mixed
84
    {
85
        return $this->requestStack->getSession()->get(self::SESSION_PATH . $key);
86
    }
87
}
88