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 RangeConstraintBuilder implements ConstraintBuilderInterface  | 
            ||
| 17 | { | 
            ||
| 18 | |||
| 19 | /**  | 
            ||
| 20 | * @var array  | 
            ||
| 21 | */  | 
            ||
| 22 | private $types = [  | 
            ||
| 23 | 'Range',  | 
            ||
| 24 | 'GreaterThanOrEqual',  | 
            ||
| 25 | 'LessThanOrEqual'  | 
            ||
| 26 | ];  | 
            ||
| 27 | |||
| 28 | /**  | 
            ||
| 29 | * @var string  | 
            ||
| 30 | */  | 
            ||
| 31 | private $type;  | 
            ||
| 32 | |||
| 33 | /**  | 
            ||
| 34 | * if this builder supports a given constraint  | 
            ||
| 35 | *  | 
            ||
| 36 | * @param string $type Field type  | 
            ||
| 37 | * @param array $options Options  | 
            ||
| 38 | *  | 
            ||
| 39 | * @return bool  | 
            ||
| 40 | */  | 
            ||
| 41 | public function supportsConstraint($type, array $options = [])  | 
            ||
| 50 | |||
| 51 | /**  | 
            ||
| 52 | * Adds constraints to the property  | 
            ||
| 53 | *  | 
            ||
| 54 | * @param string $fieldName field name  | 
            ||
| 55 | * @param Schema $property property  | 
            ||
| 56 | * @param DocumentModel $model parent model  | 
            ||
| 57 | * @param array $options the constraint options  | 
            ||
| 58 | *  | 
            ||
| 59 | * @return Schema the modified property  | 
            ||
| 60 | */  | 
            ||
| 61 | public function buildConstraint($fieldName, Schema $property, DocumentModel $model, array $options)  | 
            ||
| 80 | }  | 
            ||
| 81 | 
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.