OptimusDriver::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 10
cc 3
nc 2
nop 1
crap 3
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 Optimus driver instance.
19
     *
20
     * @param  array  $config
21
     *
22
     * @throws \InvalidArgumentException
23
     */
24 20
    public function __construct(array $config)
25
    {
26 20
        if (! isset($config['prime'], $config['inverse'])) {
27 12
            throw new InvalidArgumentException('prime and inverse must be specified.');
28
        }
29
30 8
        $this->optimus = new Optimus(
31 8
            $config['prime'],
32 8
            $config['inverse'],
33 8
            isset($config['random']) ? $config['random'] : 0
34 4
        );
35 4
    }
36
37
    /**
38
     * Encode the data.
39
     *
40
     * @param  int  $data
41
     * @return int
42
     */
43 4
    public function encode($data)
44
    {
45 4
        return $this->optimus->encode($data);
46
    }
47
48
    /**
49
     * Decode the data.
50
     *
51
     * @param  int  $data
52
     * @return int
53
     */
54 4
    public function decode($data)
55
    {
56 4
        return $this->optimus->decode($data);
57
    }
58
}
59