Completed
Push — master ( a6e8b1...08dd78 )
by Elf
01:49
created

Base64Driver   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 43
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A encode() 0 4 1
A decode() 0 6 2
1
<?php
2
3
namespace ElfSundae\Laravel\Hashid;
4
5
use Illuminate\Support\Arr;
6
7
class Base64Driver 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 urlsafe_base64_encode($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
        $data = urlsafe_base64_decode($data);
46
47 1
        return $this->integer ? (int) $data : $data;
48
    }
49
}
50