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

Base64Connection::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 1
cts 1
cp 1
crap 1
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