Completed
Push — master ( 6626dc...4677af )
by Elf
02:10
created

HashidsDriver::encode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace ElfSundae\Laravel\Hashid;
4
5
use Hashids\Hashids;
6
use Illuminate\Support\Arr;
7
8
class HashidsDriver implements DriverInterface
9
{
10
    /**
11
     * The Hashids instance.
12
     *
13
     * @var \Hashids\Hashids
14
     */
15
    protected $hashids;
16
17
    /**
18
     * Create a new hashid driver instance.
19
     *
20
     * @param  array  $config
21
     */
22 2
    public function __construct(array $config = [])
23
    {
24 2
        $this->hashids = new Hashids(
25 2
            Arr::get($config, 'salt', ''),
26 2
            Arr::get($config, 'min_length', 0),
27 2
            Arr::get($config, 'alphabet', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890')
28 2
        );
29 2
    }
30
31
    /**
32
     * Encode the data.
33
     *
34
     * @param  mixed  $data
35
     * @return string
36
     */
37 1
    public function encode($data)
38
    {
39 1
        return $this->hashids->encode($data);
40
    }
41
42
    /**
43
     * Decode the data.
44
     *
45
     * @param  mixed  $data
46
     * @return mixed
47
     */
48
    public function decode($data)
49
    {
50
        return $this->hashids->decode($data);
51
    }
52
}
53