Completed
Push — master ( 017bea...40ea99 )
by Elf
01:25
created

HexDriver   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 41
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A encode() 0 4 2
A decode() 0 4 2
1
<?php
2
3
namespace ElfSundae\Laravel\Hashid;
4
5
use Illuminate\Support\Arr;
6
7
class HexDriver implements DriverInterface
8
{
9
    /**
10
     * Indicates integer encoding.
11
     *
12
     * @var bool
13
     */
14
    protected $integer = false;
15
16
    /**
17
     * Create a new hashid driver instance.
18
     *
19
     * @param  array  $config
20
     */
21 2
    public function __construct(array $config = [])
22
    {
23 2
        $this->integer = Arr::get($config, 'integer', $this->integer);
24 2
    }
25
26
    /**
27
     * Encode the data.
28
     *
29
     * @param  mixed  $data
30
     * @return string
31
     */
32 1
    public function encode($data)
33
    {
34 1
        return $this->integer ? dechex($data) : bin2hex($data);
35
    }
36
37
    /**
38
     * Decode the data.
39
     *
40
     * @param  string  $data
41
     * @return mixed
42
     */
43 1
    public function decode($data)
44
    {
45 1
        return $this->integer ? hexdec($data) : hex2bin($data);
46
    }
47
}
48