SessionTokenStorage::set()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 2
rs 10
1
<?php
2
namespace Ubiquity\security\csrf\storages;
3
4
use Ubiquity\utils\http\USession;
5
6
class SessionTokenStorage implements TokenStorageInterface {
7
8
	protected $key = '_CSRF';
9
10
	protected function getKey($id) {
11
		return $this->key . '/' . $id;
12
	}
13
14
	public function __construct(string $key = '_CSRF') {
15
		$this->key = $key;
16
	}
17
18
	public function set(string $id, string $token): void {
19
		USession::set($this->getKey($id), $token);
20
	}
21
22
	public function get(string $id): ?string {
23
		return USession::get($this->getKey($id));
24
	}
25
26
	public function exists(string $id): bool {
27
		return USession::exists($this->getKey($id));
28
	}
29
30
	public function remove(string $id): ?string {
31
		$v = USession::get($id);
32
		USession::delete($this->getKey($id));
33
		return $v;
34
	}
35
}
36
37