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  | 
            ||
| 16 | class APCStore extends CacheStore  | 
            ||
| 17 | { | 
            ||
| 18 | /**  | 
            ||
| 19 | * Cache driver types.  | 
            ||
| 20 | */  | 
            ||
| 21 | const APC_DRIVER = 0;  | 
            ||
| 22 | const APCU_DRIVER = 1;  | 
            ||
| 23 | |||
| 24 | /**  | 
            ||
| 25 |      * {@inheritdoc} | 
            ||
| 26 | */  | 
            ||
| 27 | private $prefix;  | 
            ||
| 28 | |||
| 29 | /**  | 
            ||
| 30 | * Cache driver type.  | 
            ||
| 31 | *  | 
            ||
| 32 | * @var int  | 
            ||
| 33 | */  | 
            ||
| 34 | private $driverType;  | 
            ||
| 35 | |||
| 36 | /**  | 
            ||
| 37 | * @param string $prefix  | 
            ||
| 38 | */  | 
            ||
| 39 | public function __construct(string $prefix = 'spiral:')  | 
            ||
| 40 |     { | 
            ||
| 41 | $this->prefix = $prefix;  | 
            ||
| 42 | |||
| 43 |         $this->driverType = function_exists('apcu_store') ? self::APCU_DRIVER : self::APC_DRIVER; | 
            ||
| 44 | }  | 
            ||
| 45 | |||
| 46 | /**  | 
            ||
| 47 | * Get APC cache type (APC or APCU).  | 
            ||
| 48 | *  | 
            ||
| 49 | * @see APCStore::APC_DRIVER  | 
            ||
| 50 | * @see APCStore::APCU_DRIVER  | 
            ||
| 51 | * @return int  | 
            ||
| 52 | */  | 
            ||
| 53 | public function getDriver(): int  | 
            ||
| 57 | |||
| 58 | /**  | 
            ||
| 59 |      * {@inheritdoc} | 
            ||
| 60 | */  | 
            ||
| 61 | public function isAvailable(): bool  | 
            ||
| 65 | |||
| 66 | /**  | 
            ||
| 67 |      * {@inheritdoc} | 
            ||
| 68 | */  | 
            ||
| 69 | public function has(string $name): bool  | 
            ||
| 77 | |||
| 78 | /**  | 
            ||
| 79 |      * {@inheritdoc} | 
            ||
| 80 | */  | 
            ||
| 81 | public function get(string $name)  | 
            ||
| 89 | |||
| 90 | /**  | 
            ||
| 91 |      * {@inheritdoc} | 
            ||
| 92 | */  | 
            ||
| 93 | public function set(string $name, $data, $ttl = null)  | 
            ||
| 101 | |||
| 102 | /**  | 
            ||
| 103 |      * {@inheritdoc} | 
            ||
| 104 | */  | 
            ||
| 105 | public function delete(string $name)  | 
            ||
| 115 | |||
| 116 | /**  | 
            ||
| 117 |      * {@inheritdoc} | 
            ||
| 118 | */  | 
            ||
| 119 | View Code Duplication | public function inc(string $name, int $delta = 1): int  | 
            |
| 127 | |||
| 128 | /**  | 
            ||
| 129 |      * {@inheritdoc} | 
            ||
| 130 | */  | 
            ||
| 131 | View Code Duplication | public function dec(string $name, int $delta = 1): int  | 
            |
| 139 | |||
| 140 | /**  | 
            ||
| 141 |      * {@inheritdoc} | 
            ||
| 142 | */  | 
            ||
| 143 | public function clear()  | 
            ||
| 153 | }  | 
            ||
| 154 | 
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.