Passed
Pull Request — master (#81)
by Zing
06:27
created

VerificationCodeManager::getPrefixedKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Zing\LaravelSms;
6
7
use Illuminate\Contracts\Cache\Factory;
8
9
class VerificationCodeManager
10
{
11
    protected $cacheManager;
12
13
    /**
14
     * VerificationCodeManager constructor.
15
     *
16
     * @param $cacheManager
17
     */
18 2
    public function __construct(Factory $cacheManager)
19
    {
20 2
        $this->cacheManager = $cacheManager;
21 2
    }
22
23 2
    protected function getPrefixedKey($number)
24
    {
25 2
        return config('sms.verification.prefix') . $number;
26
    }
27
28 1
    public function verify($number, $code)
29
    {
30 1
        return $code === $this->cacheManager->get($this->getPrefixedKey($number));
31
    }
32
33 2
    public function issue($number)
34
    {
35 2
        $length = config('sms.verification.length');
36 2
        $code = random_int(10 ** ($length - 1), (10 ** $length) - 1);
37 2
        $this->cacheManager->set($this->getPrefixedKey($number), $code, 600);
38
39 2
        return $code;
40
    }
41
}
42