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  | 
            ||
| 9 | class Cache implements CacheInterface  | 
            ||
| 10 | { | 
            ||
| 11 | /**  | 
            ||
| 12 | * Cache.  | 
            ||
| 13 | *  | 
            ||
| 14 | * @var object  | 
            ||
| 15 | */  | 
            ||
| 16 | protected $manager;  | 
            ||
| 17 | |||
| 18 | /**  | 
            ||
| 19 | * Config.  | 
            ||
| 20 | *  | 
            ||
| 21 | * @var Config  | 
            ||
| 22 | */  | 
            ||
| 23 | protected $config;  | 
            ||
| 24 | |||
| 25 | /**  | 
            ||
| 26 | * Cache directory.  | 
            ||
| 27 | *  | 
            ||
| 28 | * @var string  | 
            ||
| 29 | */  | 
            ||
| 30 | protected $dir;  | 
            ||
| 31 | |||
| 32 | /**  | 
            ||
| 33 | * Cache constructor.  | 
            ||
| 34 | * @param object $config  | 
            ||
| 35 | * @param object $manager  | 
            ||
| 36 | * @param null $path  | 
            ||
| 37 | */  | 
            ||
| 38 | 31 | public function __construct($config = null, $manager = null, $path = null)  | 
            |
| 44 | |||
| 45 | /**  | 
            ||
| 46 | * Instantiate the config.  | 
            ||
| 47 | *  | 
            ||
| 48 | * @param $config  | 
            ||
| 49 | * @return Config|mixed  | 
            ||
| 50 | */  | 
            ||
| 51 | 31 | public function instantiateConfig($config)  | 
            |
| 55 | |||
| 56 | /**  | 
            ||
| 57 | * Instantiate the cache manager.  | 
            ||
| 58 | *  | 
            ||
| 59 | * @param $config  | 
            ||
| 60 | * @param $manager  | 
            ||
| 61 | * @param $path  | 
            ||
| 62 | * @return NetteManager|mixed  | 
            ||
| 63 | */  | 
            ||
| 64 | 31 | public function instantiateManager($config, $manager, $path)  | 
            |
| 70 | |||
| 71 | /**  | 
            ||
| 72 | * Check if cache is enabled.  | 
            ||
| 73 | *  | 
            ||
| 74 | * @return bool  | 
            ||
| 75 | */  | 
            ||
| 76 | 31 | protected function enabled()  | 
            |
| 80 | |||
| 81 | /**  | 
            ||
| 82 | * Fetches a value from the cache.  | 
            ||
| 83 | *  | 
            ||
| 84 | * @param string $key  | 
            ||
| 85 | * @param null $default  | 
            ||
| 86 | * @return mixed|null  | 
            ||
| 87 | */  | 
            ||
| 88 | 31 | public function get($key, $default = null)  | 
            |
| 96 | |||
| 97 | /**  | 
            ||
| 98 | * Create a cache key.  | 
            ||
| 99 | *  | 
            ||
| 100 | * @return string  | 
            ||
| 101 | * @throws Exception  | 
            ||
| 102 | */  | 
            ||
| 103 | 31 | public function makeKey()  | 
            |
| 113 | |||
| 114 | /**  | 
            ||
| 115 | * Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time.  | 
            ||
| 116 | *  | 
            ||
| 117 | * @param string $key  | 
            ||
| 118 | * @param mixed $value  | 
            ||
| 119 | * @param null $ttl  | 
            ||
| 120 | * @return bool  | 
            ||
| 121 | */  | 
            ||
| 122 | 31 | public function set($key, $value, $ttl = null)  | 
            |
| 130 | |||
| 131 | /**  | 
            ||
| 132 | * Delete an item from the cache by its unique key.  | 
            ||
| 133 | *  | 
            ||
| 134 | * @param string $key  | 
            ||
| 135 | * @return bool  | 
            ||
| 136 | */  | 
            ||
| 137 | public function delete($key)  | 
            ||
| 141 | |||
| 142 | /**  | 
            ||
| 143 | * Wipe clean the entire cache's keys.  | 
            ||
| 144 | */  | 
            ||
| 145 | 31 | public function clear()  | 
            |
| 149 | |||
| 150 | /**  | 
            ||
| 151 | * Obtains multiple cache items by their unique keys.  | 
            ||
| 152 | *  | 
            ||
| 153 | * @param $keys  | 
            ||
| 154 | * @param null $default  | 
            ||
| 155 | * @return array  | 
            ||
| 156 | */  | 
            ||
| 157 | public function getMultiple($keys, $default = null)  | 
            ||
| 161 | |||
| 162 | /**  | 
            ||
| 163 | * Persists a set of key => value pairs in the cache, with an optional TTL.  | 
            ||
| 164 | *  | 
            ||
| 165 | * @param $values  | 
            ||
| 166 | * @param null $ttl  | 
            ||
| 167 | * @return bool  | 
            ||
| 168 | */  | 
            ||
| 169 | public function setMultiple($values, $ttl = null)  | 
            ||
| 173 | |||
| 174 | /**  | 
            ||
| 175 | * Deletes multiple cache items in a single operation.  | 
            ||
| 176 | *  | 
            ||
| 177 | * @param $keys  | 
            ||
| 178 | * @return bool|void  | 
            ||
| 179 | */  | 
            ||
| 180 | public function deleteMultiple($keys)  | 
            ||
| 184 | |||
| 185 | /**  | 
            ||
| 186 | * Determines whether an item is present in the cache.  | 
            ||
| 187 | *  | 
            ||
| 188 | * @param string $key  | 
            ||
| 189 | * @return bool  | 
            ||
| 190 | */  | 
            ||
| 191 | public function has($key)  | 
            ||
| 195 | |||
| 196 | /**  | 
            ||
| 197 | * Get an item from the cache, or store the default value.  | 
            ||
| 198 | *  | 
            ||
| 199 | * @param string $key  | 
            ||
| 200 | * @param \DateTimeInterface|\DateInterval|float|int $minutes  | 
            ||
| 201 | * @param Closure $callback  | 
            ||
| 202 | * @return mixed  | 
            ||
| 203 | */  | 
            ||
| 204 | View Code Duplication | public function remember($key, $minutes, Closure $callback)  | 
            |
| 214 | }  | 
            ||
| 215 | 
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.