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 | ||
| 7 | View Code Duplication | class StrBetween extends AbstractStringCase implements SanitizeRuleInterface | |
|  | |||
| 8 | { | ||
| 9 | /** @var int */ | ||
| 10 | protected $min; | ||
| 11 | |||
| 12 | /** @var int */ | ||
| 13 | protected $max; | ||
| 14 | |||
| 15 | /** @var string */ | ||
| 16 | protected $padString; | ||
| 17 | |||
| 18 | /** @var int */ | ||
| 19 | protected $padType; | ||
| 20 | |||
| 21 | /** | ||
| 22 | * @param int $min The minimum length. | ||
| 23 | * @param int $max The maximum length. | ||
| 24 | * @param string $pad_string Pad using this string. | ||
| 25 | * @param int $pad_type A `STR_PAD_*` constant. | ||
| 26 | * | ||
| 27 | */ | ||
| 28 | 39 | public function __construct(int $min, int $max, string $padString = ' ', int $padType = STR_PAD_RIGHT) | |
| 35 | |||
| 36 | /** | ||
| 37 | * Sanitizes a string to a length range by padding or chopping it. | ||
| 38 | * | ||
| 39 | * @param object $subject The subject to be filtered. | ||
| 40 | * @param string $field The subject field name. | ||
| 41 | * | ||
| 42 | * @return bool True if the value was sanitized, false if not. | ||
| 43 | */ | ||
| 44 | 39 | public function __invoke($subject, string $field): bool | |
| 59 | } | ||
| 60 | 
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.