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 |
||
| 29 | class Driver implements ExtendedCacheItemPoolInterface |
||
| 30 | { |
||
| 31 | use DriverBaseTrait; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var CouchbaseClient |
||
| 35 | */ |
||
| 36 | public $instance; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var \CouchbaseBucket[] |
||
| 40 | */ |
||
| 41 | protected $bucketInstances = []; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var string |
||
| 45 | */ |
||
| 46 | protected $bucketCurrent = ''; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Driver constructor. |
||
| 50 | * @param array $config |
||
| 51 | * @throws phpFastCacheDriverException |
||
| 52 | */ |
||
| 53 | public function __construct(array $config = []) |
||
| 54 | { |
||
| 55 | $this->setup($config); |
||
| 56 | |||
| 57 | View Code Duplication | if (!$this->driverCheck()) { |
|
| 58 | throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName())); |
||
| 59 | } else { |
||
| 60 | $this->driverConnect(); |
||
| 61 | } |
||
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @return bool |
||
| 66 | */ |
||
| 67 | public function driverCheck() |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @param \Psr\Cache\CacheItemInterface $item |
||
| 74 | * @return mixed |
||
| 75 | * @throws \InvalidArgumentException |
||
| 76 | */ |
||
| 77 | protected function driverWrite(CacheItemInterface $item) |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @param \Psr\Cache\CacheItemInterface $item |
||
| 91 | * @return mixed |
||
| 92 | */ |
||
| 93 | protected function driverRead(CacheItemInterface $item) |
||
| 104 | |||
| 105 | /** |
||
| 106 | * @param \Psr\Cache\CacheItemInterface $item |
||
| 107 | * @return bool |
||
| 108 | * @throws \InvalidArgumentException |
||
| 109 | */ |
||
| 110 | protected function driverDelete(CacheItemInterface $item) |
||
| 121 | |||
| 122 | /** |
||
| 123 | * @return bool |
||
| 124 | */ |
||
| 125 | protected function driverClear() |
||
| 129 | |||
| 130 | /** |
||
| 131 | * @return bool |
||
| 132 | */ |
||
| 133 | protected function driverConnect() |
||
| 160 | |||
| 161 | /** |
||
| 162 | * @return \CouchbaseBucket |
||
| 163 | */ |
||
| 164 | protected function getBucket() |
||
| 168 | |||
| 169 | /** |
||
| 170 | * @param $bucketName |
||
| 171 | * @param \CouchbaseBucket $CouchbaseBucket |
||
| 172 | * @throws \LogicException |
||
| 173 | */ |
||
| 174 | protected function setBucket($bucketName, \CouchbaseBucket $CouchbaseBucket) |
||
| 182 | |||
| 183 | /******************** |
||
| 184 | * |
||
| 185 | * PSR-6 Extended Methods |
||
| 186 | * |
||
| 187 | *******************/ |
||
| 188 | |||
| 189 | /** |
||
| 190 | * @return driverStatistic |
||
| 191 | */ |
||
| 192 | public function getStats() |
||
| 202 | } |