Completed
Push — master ( 9728f4...e49168 )
by Elf
07:34
created

Base62Connection::decode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

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
1
<?php
2
3
namespace ElfSundae\Laravel\Hashid;
4
5
use Tuupola\Base62;
6
use Illuminate\Support\Arr;
7
8
class Base62Connection extends Connection
9
{
10
    /**
11
     * The Base62 instance.
12
     *
13
     * @var \Tuupola\Base62
14
     */
15
    protected $base62;
16
17
    /**
18
     * Indicates encoding to and from integer.
19
     *
20
     * @var bool
21
     */
22
    protected $integer = false;
23
24
    /**
25
     * Create a new hashid connection instance.
26
     *
27
     * @param  \Illuminate\Foundation\Application  $app
28
     * @param  array  $config
29
     */
30
    public function __construct($app, array $config = [])
31
    {
32
        parent::__construct($app, $config);
33
34
        $this->base62 = new Base62(
35
            array_filter(Arr::only($config, ['characters']))
36
        );
37
38
        $this->integer = Arr::get($config, 'integer', false);
39
    }
40
41
    /**
42
     * Encode the given data.
43
     *
44
     * @param  mixed  $data
45
     * @return mixed
46
     */
47
    public function encode($data)
48
    {
49
        return $this->base62->encode($data);
50
    }
51
52
    /**
53
     * Decode the given data.
54
     *
55
     * @param  mixed  $data
56
     * @return mixed
57
     */
58
    public function decode($data)
59
    {
60
        return $this->base62->decode($data, $this->integer);
61
    }
62
}
63