LaravelDriver::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
namespace hamburgscleanest\GuzzleAdvancedThrottle\Cache\Drivers;
4
5
use Illuminate\Container\Container;
6
7
8
abstract class LaravelDriver
9
{
10
    /** @var string */
11
    private const DEFAULT_CACHE_PREFIX = 'throttle_cache';
12
13
    protected Container $_container;
14
    protected string $_driver;
15
    protected array $_options;
16
    private string $_driverStoreKey;
17
18 15
    public function __construct(string $driver, array $options = [])
19
    {
20 15
        $this->_container = new Container();
21 15
        $this->_driver = $driver;
22 15
        $this->_driverStoreKey = 'cache.stores.' . $this->_driver;
23 15
        $this->_options = $options;
24 15
    }
25
26 15
    public function getContainer(): Container
27
    {
28 15
        $this->_setConfig();
29 15
        $this->_setContainer();
30
31 13
        return $this->_container;
32
    }
33
34
    abstract protected function _setContainer(): void;
35
36 15
    private function _setConfig(): void
37
    {
38 15
        $this->_container['config'] = [
39 15
            'cache.default'        => $this->_driver,
40 15
            $this->_driverStoreKey => ['driver' => $this->_driver] + $this->_options,
41 15
            'cache.prefix'         => $this->_options['cache_prefix'] ?? self::DEFAULT_CACHE_PREFIX
42
        ];
43 15
    }
44
45 2
    protected function _setStoreValue(string $key, $value): void
46
    {
47 2
        $this->_container->offsetSet('config.' . $this->_driverStoreKey . '.' . $key, $value);
48 2
    }
49
}
50