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