HashidsDriver::encode()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
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 Hashids driver instance.
19
     *
20
     * @param  array  $config
21
     */
22 8
    public function __construct(array $config = [])
23
    {
24 8
        $this->hashids = new Hashids(
25 8
            Arr::get($config, 'salt', ''),
26 8
            Arr::get($config, 'min_length', 0),
27 8
            Arr::get($config, 'alphabet', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890')
28 4
        );
29 4
    }
30
31
    /**
32
     * Encode the data.
33
     *
34
     * @param  mixed  $data
35
     * @return string
36
     */
37 4
    public function encode($data)
38
    {
39 4
        return $this->hashids->encode($data);
40
    }
41
42
    /**
43
     * Decode the data.
44
     *
45
     * @param  mixed  $data
46
     * @return mixed
47
     */
48 4
    public function decode($data)
49
    {
50 4
        return $this->hashids->decode($data);
51
    }
52
}
53