Completed
Push — master ( fc124a...01526a )
by Elf
03:55
created

OptimusDriver::decode()   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 InvalidArgumentException;
6
use Jenssegers\Optimus\Optimus;
7
8
class OptimusDriver implements DriverInterface
9
{
10
    /**
11
     * The Optimus instance.
12
     *
13
     * @var \Jenssegers\Optimus\Optimus
14
     */
15
    protected $optimus;
16
17
    /**
18
     * Create a new hashid driver instance.
19
     *
20
     * @param  array  $config
21
     *
22
     * @throws \InvalidArgumentException
23
     */
24 5
    public function __construct(array $config)
25
    {
26 5
        if (! isset($config['prime'], $config['inverse'])) {
27 3
            throw new InvalidArgumentException('prime and inverse must be specified.');
28
        }
29
30 2
        $this->optimus = new Optimus(
31 2
            $config['prime'],
32 2
            $config['inverse'],
33 2
            isset($config['random']) ? $config['random'] : 0
34 2
        );
35 2
    }
36
37
    /**
38
     * Encode the data.
39
     *
40
     * @param  int  $data
41
     * @return int
42
     */
43 1
    public function encode($data)
44
    {
45 1
        return $this->optimus->encode($data);
46
    }
47
48
    /**
49
     * Decode the data.
50
     *
51
     * @param  int  $data
52
     * @return int
53
     */
54 1
    public function decode($data)
55
    {
56 1
        return $this->optimus->decode($data);
57
    }
58
}
59