Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php namespace Comodojo\SimpleCache\Providers; |
||
25 | abstract class AbstractProvider implements CacheInterface { |
||
26 | |||
27 | /** |
||
28 | * Current logger |
||
29 | * |
||
30 | * @var LoggerInterface |
||
31 | */ |
||
32 | protected $logger; |
||
33 | |||
34 | protected $driver; |
||
35 | |||
36 | /** |
||
37 | * Class constructor |
||
38 | * |
||
39 | * @throws \Comodojo\Exception\CacheException |
||
40 | */ |
||
41 | 141 | public function __construct(LoggerInterface $logger = null) { |
|
46 | |||
47 | /** |
||
48 | * {@inheritdoc} |
||
49 | */ |
||
50 | public function getLogger() { |
||
55 | |||
56 | /** |
||
57 | * {@inheritdoc} |
||
58 | */ |
||
59 | 141 | View Code Duplication | public function setLogger(LoggerInterface $logger = null) { |
66 | |||
67 | abstract public function get($key, $default = null); |
||
68 | |||
69 | abstract public function set($key, $value, $ttl = null); |
||
70 | |||
71 | abstract public function delete($key); |
||
72 | |||
73 | abstract public function clear(); |
||
74 | |||
75 | abstract public function getMultiple($keys, $default = null); |
||
76 | |||
77 | abstract public function setMultiple($values, $ttl = null); |
||
78 | |||
79 | abstract public function deleteMultiple($keys); |
||
80 | |||
81 | abstract public function has($key); |
||
82 | |||
83 | } |
||
84 |
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.