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 |
||
| 29 | class DocumentFixtures |
||
| 30 | { |
||
| 31 | /** |
||
| 32 | * Loads empty document data. |
||
| 33 | * |
||
| 34 | * @return DocumentData |
||
| 35 | */ |
||
| 36 | public static function getEmptyDocumentData() |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Loads document data. |
||
| 43 | * |
||
| 44 | * @return DocumentData |
||
| 45 | */ |
||
| 46 | public static function getDocumentData() |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Loads an activity profile document. |
||
| 53 | * |
||
| 54 | * @param DocumentData $documentData The document data, by default, a some |
||
| 55 | * default data will be used |
||
| 56 | * |
||
| 57 | * @return ActivityProfileDocument |
||
| 58 | */ |
||
| 59 | View Code Duplication | public static function getActivityProfileDocument(DocumentData $documentData = null) |
|
| 69 | |||
| 70 | /** |
||
| 71 | * Loads an agent profile document. |
||
| 72 | * |
||
| 73 | * @param DocumentData $documentData The document data, by default, a some |
||
| 74 | * default data will be used |
||
| 75 | * |
||
| 76 | * @return AgentProfileDocument |
||
| 77 | */ |
||
| 78 | public static function getAgentProfileDocument(DocumentData $documentData = null) |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Loads a state document. |
||
| 89 | * |
||
| 90 | * @param DocumentData $documentData The document data, by default, a some |
||
| 91 | * default data will be used |
||
| 92 | * |
||
| 93 | * @return StateDocument |
||
| 94 | */ |
||
| 95 | View Code Duplication | public static function getStateDocument(DocumentData $documentData = null) |
|
| 106 | } |
||
| 107 |
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.