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

InvitationToken::generate()   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 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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