Test Failed
Push — master ( 08bde6...dbe2a2 )
by Ricardo
04:00
created

Phone::generate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 3
nop 2
dl 0
loc 13
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Validate;
4
5
use Validate\Traits\FakeNameTrait;
6
7
class Phone implements \Validate\Contracts\Validate
8
{
9
    use FakeNameTrait;
10
11
    public static function toDatabase(string $phone)
12
    {
13
        // Change @todo
14
        return md5($phone);
15
    }
16
17
    public static function toUser($phone)
18
    {
19
        return $phone;
20
    }
21
22
    public static function generate(
23
        $length = 8,
24
        $keyspace = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%'
25
    ) {
26
        $str = '';
27
        $max = mb_strlen($keyspace, '8bit') - 1;
28
        if ($max < 1) {
29
            throw new Exception('$keyspace must be at least two characters long');
0 ignored issues
show
Bug introduced by
The type Validate\Exception was not found. Did you mean Exception? If so, make sure to prefix the type with \.
Loading history...
30
        }
31
        for ($i = 0; $i < $length; ++$i) {
32
            $str .= $keyspace[random_int(0, $max)];
33
        }
34
        return $str;
35
    }
36
37
}
38