Passed
Push — main ( 69451c...874877 )
by Garbuz
03:25
created

Config::isAutoClear()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Garbuzivan\Laraveltokens;
6
7
use Garbuzivan\Laraveltokens\Repositories\AccessTokenRepository;
8
9
class Config
10
{
11
    /**
12
     * Соль для сигнатур
13
     * @var string
14
     */
15
    protected string $salt = 'Fo3SMqqUbrxKJMQW0sVOB4Q';
16
17
    /**
18
     * Название конфигурационного файла
19
     * @var string
20
     */
21
    protected string $configName = 'laraveltokens';
22
23
    /**
24
     * Хранение в токена в открытом или зашифрованном виде
25
     * Зашифрованный тип хранения отключает возможность просматривать токен или вносить его вручную
26
     * @var bool
27
     */
28
    protected bool $encryption = false;
29
30
    /**
31
     * Автоматическое удаление токенов с законченым сроком действия
32
     * @var  bool
33
     */
34
    protected bool $autoClear = true;
35
36
    /**
37
     * Пауза перед автоматическим удалением токенов в секундах
38
     * @var  int
39
     */
40
    protected int $autoClearPause = 8640000;
41
42
    /**
43
     * Репозиторий
44
     * @var string
45
     */
46
    protected string $repository = AccessTokenRepository::class;
47
48
    /**
49
     * Фиксация последней активности токена
50
     * @var  bool
51
     */
52
    protected bool $lastUse = true;
53
54
    /**
55
     * Режим JWT
56
     * @var  bool
57
     */
58
    protected bool $jwt = true;
59
60
    /**
61
     * Configuration constructor.
62
     */
63
    public function __construct()
64
    {
65
        $this->load();
66
    }
67
68
    /**
69
     * Загрузка данных из конфигурационного файла
70
     * @return $this|Config
71
     */
72
    public function load(): Config
73
    {
74
        $this->encryption = (bool)config($this->configName . '.encryption', $this->encryption);
75
        $this->autoClear = (bool)config($this->configName . '.auto_clear', $this->autoClear);
76
        $this->autoClearPause = intval(config($this->configName . '.auto_clear_pause', $this->autoClearPause));
77
        $this->repository = (string)config($this->configName . '.repository', $this->repository);
78
        $this->lastUse = (bool)config($this->configName . '.last_use', $this->lastUse);
79
        $this->jwt = (bool)config($this->configName . '.jwt', $this->jwt);
80
        $this->salt = (string)config($this->configName . '.salt', $this->salt);
81
        $this->salt = file_exists($this->salt) ? file_get_contents($this->salt) : $this->salt;
82
        return $this;
83
    }
84
85
    /**
86
     * Проверка на шифрование токена
87
     * @return bool
88
     */
89
    public function isEncryption(): bool
90
    {
91
        return $this->encryption;
92
    }
93
94
    /**
95
     * Проверка на автоочистку от неиспользуемых токенов
96
     * @return bool
97
     */
98
    public function isAutoClear(): bool
99
    {
100
        return $this->autoClear;
101
    }
102
103
    /**
104
     * Проверка на автоочистку от неиспользуемых токенов
105
     * @return int
106
     */
107
    public function getAutoClearPause(): int
108
    {
109
        return $this->autoClearPause;
110
    }
111
112
    /**
113
     * Репозиторий
114
     * @return string
115
     */
116
    public function getRepository(): string
117
    {
118
        return $this->repository;
119
    }
120
121
    /**
122
     * Обновлять последнюю активность токена Да\Нет
123
     * @return bool
124
     */
125
    public function isLastUse(): bool
126
    {
127
        return $this->lastUse;
128
    }
129
130
    /**
131
     * Режим JWT
132
     * @return bool
133
     */
134
    public function isJwt(): bool
135
    {
136
        return $this->jwt;
137
    }
138
139
    /**
140
     * Режим JWT
141
     * @return string
142
     */
143
    public function getSalt(): string
144
    {
145
        return $this->salt;
146
    }
147
}
148