Passed
Push — master ( 0f8e83...edb234 )
by Philippe
02:11 queued 12s
created

InvitationToken::hashKey()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 10
cc 2
nc 2
nop 0
crap 2
1
<?php
2
3
namespace Thinktomorrow\Chief\Users\Invites;
4
5
use Illuminate\Support\Str;
6
7
class InvitationToken
8
{
9 17
    public static function generate()
10
    {
11 17
        return hash_hmac('sha256', Str::random(20), static::hashKey());
12
    }
13
14 17
    private static function hashKey(): string
15
    {
16 17
        $key = config('app.key');
17
18 17
        if (Str::startsWith($key, 'base64:')) {
19 17
            $key = base64_decode(substr($key, 7));
20
        }
21
22 17
        return $key;
23
    }
24
}
25