Completed
Push — master ( e49168...467919 )
by Elf
01:49
created

Base64Connection   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 1
Bugs 0 Features 0
Metric Value
dl 0
loc 43
rs 10
c 1
b 0
f 0
ccs 4
cts 4
cp 1
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 Base64Connection implements ConnectionInterface
8
{
9
    /**
10
     * Indicates encoding to integer.
11
     *
12
     * @var bool
13 1
     */
14
    protected $integer = false;
15 1
16
    /**
17
     * Create a new hashid connection instance.
18
     *
19
     * @param  array  $config
20
     */
21
    public function __construct(array $config = [])
22
    {
23
        $this->integer = Arr::get($config, 'integer', false);
24 1
    }
25
26 1
    /**
27
     * Encode the given string.
28
     *
29
     * @param  mixed  $data
30
     * @return string
31
     */
32
    public function encode($data)
33
    {
34
        return urlsafe_base64_encode($data);
35
    }
36
37
    /**
38
     * Decode the base64 encoded data.
39
     *
40
     * @param  string  $data
41
     * @return mixed
42
     */
43
    public function decode($data)
44
    {
45
        $data = urlsafe_base64_decode($data);
46
47
        return $this->integer ? (int) $data : $data;
48
    }
49
}
50