Base62Driver   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 4
eloc 7
c 3
b 0
f 0
dl 0
loc 42
ccs 9
cts 9
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A decode() 0 3 1
A __construct() 0 6 2
A encode() 0 3 1
1
<?php
2
3
namespace ElfSundae\Laravel\Hashid;
4
5
use Illuminate\Support\Arr;
6
use Tuupola\Base62\GmpEncoder;
7
use Tuupola\Base62\PhpEncoder;
8
9
class Base62Driver implements DriverInterface
10
{
11
    /**
12
     * The Base62 instance.
13
     *
14
     * @var \Tuupola\Base62\GmpEncoder|\Tuupola\Base62\PhpEncoder
15
     */
16
    protected $base62;
17
18
    /**
19
     * Create a new Base62 driver instance.
20
     *
21
     * @param  array  $config
22
     */
23 12
    public function __construct(array $config = [])
24
    {
25 12
        $options = Arr::only($config, ['characters']);
26
27 12
        $this->base62 = extension_loaded('gmp')
28 12
            ? new GmpEncoder($options) : new PhpEncoder($options);
29 6
    }
30
31
    /**
32
     * Encode the data.
33
     *
34
     * @param  string  $data
35
     * @return string
36
     */
37 8
    public function encode($data)
38
    {
39 8
        return $this->base62->encode($data);
40
    }
41
42
    /**
43
     * Decode the data.
44
     *
45
     * @param  string  $data
46
     * @return string
47
     */
48 8
    public function decode($data)
49
    {
50 8
        return $this->base62->decode($data);
51
    }
52
}
53