Conditions | 7 |
Paths | 7 |
Total Lines | 35 |
Code Lines | 28 |
Lines | 17 |
Ratio | 48.57 % |
Changes | 0 |
1 | <?php |
||
24 | public function getCacheDriver(string $cacheName): ICache |
||
25 | { |
||
26 | $driver = null; |
||
27 | $factory = new CacheDriverFactory(); |
||
28 | |||
29 | switch ($cacheName) { |
||
30 | case "apcu": |
||
31 | $driver = $factory->create("WebStream\Cache\Driver\Apcu"); |
||
32 | break; |
||
33 | View Code Duplication | case "memcached": |
|
|
|||
34 | $cacheConfig = \Spyc::YAMLLoad($this->getApplicationRoot() . '/config/cache.yml'); |
||
35 | if (array_key_exists('memcached', $cacheConfig)) { |
||
36 | $config = new Container(false); |
||
37 | $config->servers = [$cacheConfig['host'], $cacheConfig['port']]; |
||
38 | $driver = $factory->create("WebStream\Cache\Driver\Memcached", $config); |
||
39 | } |
||
40 | break; |
||
41 | View Code Duplication | case "redis": |
|
42 | $cacheConfig = \Spyc::YAMLLoad($this->getApplicationRoot() . '/config/cache.yml'); |
||
43 | if (array_key_exists('redis', $cacheConfig)) { |
||
44 | $config = new Container(false); |
||
45 | $config->host = $cacheConfig['host']; |
||
46 | $config->port = $cacheConfig['port']; |
||
47 | $driver = $factory->create("WebStream\Cache\Driver\Redis", $config); |
||
48 | } |
||
49 | break; |
||
50 | case "temporaryFile": |
||
51 | $config = new Container(); |
||
52 | $config->cacheDir = "/tmp"; |
||
53 | $driver = $factory->create("WebStream\Cache\Driver\TemporaryFile", $config); |
||
54 | break; |
||
55 | } |
||
56 | |||
57 | return $driver; |
||
58 | } |
||
59 | } |
||
60 |
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.