Passed
Push — master ( 83c445...092c55 )
by Kirill
05:01
created

CsrfConfig   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 11
c 1
b 0
f 0
dl 0
loc 52
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getTokenLength() 0 3 1
A getSameSite() 0 3 1
A getCookie() 0 3 1
A isCookieSecure() 0 3 1
A getCookieLifetime() 0 3 1
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license MIT
7
 * @author  Anton Titov (Wolfy-J)
8
 * @author  Valentin V (vvval)
9
 */
10
11
declare(strict_types=1);
12
13
namespace Spiral\Csrf\Config;
14
15
use Spiral\Core\InjectableConfig;
16
17
final class CsrfConfig extends InjectableConfig
18
{
19
    public const CONFIG = 'csrf';
20
21
    /**
22
     * @var array
23
     */
24
    protected $config = [
25
        'cookie'   => 'csrf-token',
26
        'length'   => 16,
27
        'lifetime' => 86400
28
    ];
29
30
    /**
31
     * @return int
32
     */
33
    public function getTokenLength(): int
34
    {
35
        return $this->config['length'];
36
    }
37
38
    /**
39
     * @return string
40
     */
41
    public function getCookie(): string
42
    {
43
        return $this->config['cookie'];
44
    }
45
46
47
    /**
48
     * @return int|null
49
     */
50
    public function getCookieLifetime(): ?int
51
    {
52
        return $this->config['lifetime'] ?? null;
53
    }
54
55
    /**
56
     * @return bool
57
     */
58
    public function isCookieSecure(): bool
59
    {
60
        return !empty($this->config['secure']);
61
    }
62
63
    /**
64
     * @return string|null
65
     */
66
    public function getSameSite(): ?string
67
    {
68
        return $this->config['sameSite'] ?? null;
69
    }
70
}
71