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 |
||
| 18 | class PhileToPsr16CacheAdapter implements \Phile\ServiceLocator\CacheInterface |
||
| 19 | { |
||
| 20 | /** @var string slug */ |
||
| 21 | const SLUG_PREFIX = '-phile.phpFastCache.slug-'; |
||
| 22 | |||
| 23 | const SLUG = ['{', '}' , '(', ')', '/' , '\\' , '@', ':']; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var \BasePhpFastCache the cache engine |
||
| 27 | */ |
||
| 28 | protected $cacheEngine; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * the constructor |
||
| 32 | * |
||
| 33 | * @param CacheInterface $cacheEngine |
||
| 34 | */ |
||
| 35 | 27 | public function __construct(CacheInterface $cacheEngine) |
|
| 39 | |||
| 40 | /** |
||
| 41 | * method to check if cache has entry for given key |
||
| 42 | * |
||
| 43 | * @param $key |
||
| 44 | * |
||
| 45 | * @return bool|mixed |
||
| 46 | */ |
||
| 47 | 19 | public function has($key) |
|
| 48 | { |
||
| 49 | 19 | $key = $this->slug($key); |
|
| 50 | 19 | return $this->cacheEngine->has($key); |
|
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * method to get cache entry |
||
| 55 | * |
||
| 56 | * @param string $key |
||
| 57 | * |
||
| 58 | * @return mixed|null |
||
| 59 | */ |
||
| 60 | 2 | public function get($key) |
|
| 65 | |||
| 66 | /** |
||
| 67 | * method to set cache entry |
||
| 68 | * |
||
| 69 | * @param string $key |
||
| 70 | * @param string $value |
||
| 71 | * @param int $time |
||
| 72 | * @param array $options deprecated |
||
| 73 | * |
||
| 74 | * @return mixed|void |
||
| 75 | */ |
||
| 76 | 20 | View Code Duplication | public function set($key, $value, $time = 300, array $options = array()) |
| 85 | |||
| 86 | /** |
||
| 87 | * method to delete cache entry |
||
| 88 | * |
||
| 89 | * @param string $key |
||
| 90 | * @param array $options deprecated |
||
| 91 | * |
||
| 92 | * @return mixed|void |
||
| 93 | */ |
||
| 94 | View Code Duplication | public function delete($key, array $options = array()) |
|
| 103 | |||
| 104 | /** |
||
| 105 | * clean complete cache and delete all cached entries |
||
| 106 | */ |
||
| 107 | public function clean() |
||
| 111 | |||
| 112 | /** |
||
| 113 | * replaces chars forbidden in PSR-16 cache-keys |
||
| 114 | * |
||
| 115 | * @param string $key key to slug |
||
| 116 | * @return string $key slugged key |
||
| 117 | */ |
||
| 118 | 20 | protected function slug($key) |
|
| 128 | } |
||
| 129 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..