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 | final class PackOptions |
||
| 17 | { |
||
| 18 | const FORCE_STR = 0b00000001; |
||
| 19 | const FORCE_BIN = 0b00000010; |
||
| 20 | const DETECT_STR_BIN = 0b00000100; |
||
| 21 | const FORCE_ARR = 0b00001000; |
||
| 22 | const FORCE_MAP = 0b00010000; |
||
| 23 | const DETECT_ARR_MAP = 0b00100000; |
||
| 24 | const FORCE_FLOAT32 = 0b01000000; |
||
| 25 | const FORCE_FLOAT64 = 0b10000000; |
||
| 26 | |||
| 27 | private $strBinMode; |
||
| 28 | private $arrMapMode; |
||
| 29 | private $floatMode; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @codeCoverageIgnore |
||
| 33 | */ |
||
| 34 | private function __construct() |
||
| 37 | |||
| 38 | 125 | public static function fromBitmask($options) |
|
| 61 | |||
| 62 | 110 | public function isDetectStrBinMode() |
|
| 66 | |||
| 67 | 110 | public function isForceStrMode() |
|
| 71 | |||
| 72 | 110 | public function isDetectArrMapMode() |
|
| 76 | |||
| 77 | 110 | public function isForceArrMode() |
|
| 81 | |||
| 82 | 109 | public function isForceFloat32Mode() |
|
| 86 | |||
| 87 | 125 | private static function getSingleOption($name, $options, $mask) |
|
| 112 | } |
||
| 113 |
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.