OptimusFactory::getClient()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of Laravel Optimus.
5
 *
6
 * (c) Anton Komarev <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Cog\Laravel\Optimus;
15
16
use Illuminate\Support\Arr;
17
use Jenssegers\Optimus\Optimus;
18
19
class OptimusFactory
20
{
21
    /**
22
     * Make a new Optimus client.
23
     *
24
     * @param array $config
25
     * @return \Jenssegers\Optimus\Optimus
26
     */
27
    public function make(array $config): Optimus
28
    {
29
        $config = $this->getConfig($config);
30
31
        return $this->getClient($config);
32
    }
33
34
    /**
35
     * Get the configuration data.
36
     *
37
     * @param array $config
38
     * @return array
39
     *
40
     * @throws \InvalidArgumentException
41
     */
42
    protected function getConfig(array $config): array
43
    {
44
        return [
45
            'prime' => Arr::get($config, 'prime', 0),
46
            'inverse' => Arr::get($config, 'inverse', 0),
47
            'random' => Arr::get($config, 'random', 0),
48
        ];
49
    }
50
51
    /**
52
     * Get the optimus client.
53
     *
54
     * @param array $config
55
     * @return \Jenssegers\Optimus\Optimus
56
     */
57
    protected function getClient(array $config): Optimus
58
    {
59
        return new Optimus($config['prime'], $config['inverse'], $config['random']);
60
    }
61
}
62