This class seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate
the same code in three or more different places, we strongly encourage you to
look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
21
{
22
/**
23
* @var string One of supported drivers
24
*/
25
private $driver;
26
27
/**
28
* @var array Factory supported driver
29
*/
30
private $supportedDriver = [
31
'disk' => DiskCache::class,
32
'memcached' => MemcachedCache::class,
33
];
34
35
/**
36
* @var array Options for the driver
37
*/
38
private $options;
39
40
/**
41
* Constructor.
42
*
43
* @param string $driver
44
* @param array $options
45
*/
46
3
public function __construct(string $driver, array $options)
47
{
48
3
$this->driver = $driver;
49
3
$this->options = $options;
50
3
}
51
52
/**
53
* Return Cache Resource.
54
*
55
* @throws InvalidArgumentException If required driver is not supported
56
*
57
* @return CacheInterface
58
*/
59
3
public function get() : CacheInterface
60
{
61
3
$driver = $this->driver;
62
3
$options = $this->options;
63
64
3
if (isset($this->supportedDriver[$driver])) {
65
2
$cache = $this->supportedDriver[$driver];
66
67
2
return new $cache($options);
68
}
69
70
1
throw new InvalidArgumentException("[$driver] not supported.");
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.