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 |
||
| 31 | class Driver implements ExtendedCacheItemPoolInterface |
||
| 32 | { |
||
| 33 | use DriverBaseTrait; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Driver constructor. |
||
| 37 | * @param array $config |
||
| 38 | * @throws phpFastCacheDriverException |
||
| 39 | */ |
||
| 40 | View Code Duplication | public function __construct(array $config = []) |
|
| 41 | { |
||
| 42 | $this->setup($config); |
||
| 43 | |||
| 44 | if (!$this->driverCheck()) { |
||
| 45 | throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName())); |
||
| 46 | } else { |
||
| 47 | $this->driverConnect(); |
||
| 48 | } |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @return bool |
||
| 53 | */ |
||
| 54 | public function driverCheck() |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @param \Psr\Cache\CacheItemInterface $item |
||
| 65 | * @return mixed |
||
| 66 | * @throws phpFastCacheInvalidArgumentException |
||
| 67 | */ |
||
| 68 | View Code Duplication | protected function driverWrite(CacheItemInterface $item) |
|
| 81 | |||
| 82 | /** |
||
| 83 | * @param \Psr\Cache\CacheItemInterface $item |
||
| 84 | * @return mixed |
||
| 85 | */ |
||
| 86 | View Code Duplication | protected function driverRead(CacheItemInterface $item) |
|
| 95 | |||
| 96 | /** |
||
| 97 | * @param \Psr\Cache\CacheItemInterface $item |
||
| 98 | * @return bool |
||
| 99 | * @throws phpFastCacheInvalidArgumentException |
||
| 100 | */ |
||
| 101 | protected function driverDelete(CacheItemInterface $item) |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @return bool |
||
| 115 | */ |
||
| 116 | protected function driverClear() |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @return bool |
||
| 123 | */ |
||
| 124 | protected function driverConnect() |
||
| 137 | |||
| 138 | /******************** |
||
| 139 | * |
||
| 140 | * PSR-6 Extended Methods |
||
| 141 | * |
||
| 142 | *******************/ |
||
| 143 | |||
| 144 | |||
| 145 | /** |
||
| 146 | * @return string |
||
| 147 | */ |
||
| 148 | public function getHelp() |
||
| 157 | |||
| 158 | /** |
||
| 159 | * @return DriverStatistic |
||
| 160 | */ |
||
| 161 | View Code Duplication | public function getStats() |
|
| 174 | } |