RecoveryCode   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 17
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 3 1
A __construct() 0 3 1
A equals() 0 3 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace PersonalGalaxy\Identity\Entity\Identity;
5
6
use PersonalGalaxy\Identity\TwoFactorAuthentication\Code;
7
use Innmind\Immutable\Str;
8
9
final class RecoveryCode
10
{
11
    private $value;
12
13 7
    public function __construct()
14
    {
15 7
        $this->value = (string) Str::of(bin2hex(random_bytes(16)))->substring(0, 8);
16 7
    }
17
18 5
    public function equals(Code $code): bool
19
    {
20 5
        return \hash_equals((string) $code, $this->value);
21
    }
22
23 3
    public function __toString(): string
24
    {
25 3
        return $this->value;
26
    }
27
}
28