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 VersionFieldConstraint  | 
            ||
| 17 | { | 
            ||
| 18 | /** @var ConstraintUtils */  | 
            ||
| 19 | private $utils;  | 
            ||
| 20 | |||
| 21 | /**  | 
            ||
| 22 | * Constructor  | 
            ||
| 23 | *  | 
            ||
| 24 | * @param ConstraintUtils $utils Utils  | 
            ||
| 25 | */  | 
            ||
| 26 | public function __construct(ConstraintUtils $utils)  | 
            ||
| 30 | |||
| 31 | /**  | 
            ||
| 32 | * Check if the version is correct:  | 
            ||
| 33 | * -> Post, even if posted it should be version 1  | 
            ||
| 34 | * -> Put, should be the same value. Reject if not.  | 
            ||
| 35 | * -> Patch, no check, only increment  | 
            ||
| 36 | *  | 
            ||
| 37 | * Default, if object have version as integer , increment 1.  | 
            ||
| 38 | *  | 
            ||
| 39 | * @param ConstraintEventFormat $event event class  | 
            ||
| 40 | *  | 
            ||
| 41 | * @return void  | 
            ||
| 42 | */  | 
            ||
| 43 | public function validate(ConstraintEventFormat $event)  | 
            ||
| 73 | }  | 
            ||
| 74 | 
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.