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\Cache\Drivers; |
||
| 21 | class FilesystemXattr extends AbstractDriver { |
||
| 22 | |||
| 23 | const DRIVER_NAME = "filesystem-xattr"; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Cache (files) repository |
||
| 27 | * |
||
| 28 | * @param string |
||
| 29 | */ |
||
| 30 | protected $cache_folder; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * {@inheritdoc} |
||
| 34 | */ |
||
| 35 | 47 | public function __construct(array $configuration) { |
|
| 42 | |||
| 43 | /** |
||
| 44 | * {@inheritdoc} |
||
| 45 | */ |
||
| 46 | 47 | public function test() { |
|
| 51 | |||
| 52 | /** |
||
| 53 | * {@inheritdoc} |
||
| 54 | */ |
||
| 55 | 35 | public function get($key, $namespace) { |
|
| 72 | |||
| 73 | /** |
||
| 74 | * {@inheritdoc} |
||
| 75 | */ |
||
| 76 | public function set($key, $namespace, $value, $ttl = null) { |
||
| 97 | |||
| 98 | /** |
||
| 99 | * {@inheritdoc} |
||
| 100 | */ |
||
| 101 | public function delete($key, $namespace) { |
||
| 116 | |||
| 117 | /** |
||
| 118 | * {@inheritdoc} |
||
| 119 | */ |
||
| 120 | public function clear($namespace = null) { |
||
| 121 | |||
| 122 | $result = []; |
||
| 123 | |||
| 124 | if ( $namespace === null ) { |
||
| 125 | |||
| 126 | $file_list = glob($this->cache_folder."*.cache"); |
||
| 127 | |||
| 128 | } else { |
||
| 129 | |||
| 130 | $file_list = glob($this->cache_folder."*-$namespace.cache"); |
||
| 131 | |||
| 132 | } |
||
| 133 | |||
| 134 | if ( empty($file_list) ) return true; |
||
| 135 | |||
| 136 | foreach ( $file_list as $file ) $result[] = unlink($file); |
||
| 137 | |||
| 138 | return !in_array(false, $result); |
||
| 139 | |||
| 140 | } |
||
| 141 | |||
| 142 | /** |
||
| 143 | * {@inheritdoc} |
||
| 144 | */ |
||
| 145 | 2 | View Code Duplication | public function getMultiple(array $keys, $namespace) { |
| 156 | |||
| 157 | /** |
||
| 158 | * {@inheritdoc} |
||
| 159 | */ |
||
| 160 | 1 | View Code Duplication | public function setMultiple(array $key_values, $namespace, $ttl = null) { |
| 171 | |||
| 172 | /** |
||
| 173 | * {@inheritdoc} |
||
| 174 | */ |
||
| 175 | 3 | View Code Duplication | public function deleteMultiple(array $keys, $namespace) { |
| 186 | |||
| 187 | /** |
||
| 188 | * {@inheritdoc} |
||
| 189 | */ |
||
| 190 | public function has($key, $namespace) { |
||
| 214 | |||
| 215 | /** |
||
| 216 | * {@inheritdoc} |
||
| 217 | */ |
||
| 218 | 2 | public function stats() { |
|
| 223 | |||
| 224 | } |
||
| 225 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: