Test Failed
Push — master ( bca30b...29fe32 )
by Jean-Christophe
22:16
created

CsrfToken   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 9
c 1
b 0
f 0
dl 0
loc 28
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getValue() 0 2 1
A getName() 0 2 1
A __construct() 0 3 1
A generate() 0 3 1
1
<?php
2
3
namespace Ubiquity\utils\http\session\protection;
4
5
/**
6
 * Ubiquity\utils\http\session\protection$CsrfToken
7
 * This class is part of Ubiquity
8
 *
9
 * @author jc
10
 * @version 1.0.0
11
 *
12
 */
13
class CsrfToken {
14
	private $name;
15
	private $value;
16
17
	public function __construct($size = 32) {
18
		$this->name = $this->generate ( $size );
19
		$this->value = $this->generate ( $size );
20
	}
21
22
	private function generate($size): string {
23
		$bytes = \random_bytes ( $size );
24
		return \rtrim ( \strtr ( \base64_encode ( $bytes ), '+/', '-_' ), '=' );
25
	}
26
27
	/**
28
	 *
29
	 * @return string
30
	 */
31
	public function getName() {
32
		return $this->name;
33
	}
34
35
	/**
36
	 *
37
	 * @return string
38
	 */
39
	public function getValue() {
40
		return $this->value;
41
	}
42
}
43
44