Test Failed
Push — master ( c65274...a98fd4 )
by Alexander
18:33
created

TokenRepositoryConfig   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 11
c 3
b 0
f 0
dl 0
loc 24
ccs 3
cts 3
cp 1
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getExpirePeriod() 0 4 2
A getDeliveryLimit() 0 3 2
A getVerifyLimit() 0 3 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Wearesho\Yii\Configs;
6
7
use Carbon\CarbonInterval;
8
9
use Wearesho\Yii\Interfaces\TokenRepositoryConfigInterface;
10
11
use yii\base\BaseObject;
12
use yii\base\Configurable;
13
14
class TokenRepositoryConfig extends BaseObject implements TokenRepositoryConfigInterface, Configurable
15
{
16
    public string $expirePeriodKey = 'TOKEN_EXPIRE_MINUTES';
17
    public string $verifyLimitKey = 'TOKEN_VERIFY_LIMIT';
18
    public string $deliveryLimitKey = 'TOKEN_DELIVERY_LIMIT';
19
20
    public int $defaultExpirePeriod = 30;
21
    public int $defaultVerifyLimit = 3;
22
    public int $defaultDeliveryLimit = 3;
23
24
    public function getExpirePeriod(): CarbonInterval
25
    {
26
        $minutes = (int)getenv($this->expirePeriodKey) ?: $this->defaultExpirePeriod;
27
        return CarbonInterval::minutes((int) $minutes);
28
    }
29
30 1
    public function getVerifyLimit(): int
31
    {
32 1
        return (int)getenv($this->verifyLimitKey) ?: $this->defaultVerifyLimit;
33 1
    }
34
35
    public function getDeliveryLimit(): int
36
    {
37
        return (int)getenv($this->deliveryLimitKey) ?: $this->defaultDeliveryLimit;
38
    }
39
}
40