LaravelDriver   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 4
eloc 18
c 2
b 0
f 1
dl 0
loc 40
ccs 18
cts 18
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getContainer() 0 6 1
A _setConfig() 0 6 1
A _setStoreValue() 0 3 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