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 |
||
| 11 | class NullType implements IType |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * Gets the type code |
||
| 15 | * Note: implementation of IType::getTypeCode |
||
| 16 | * |
||
| 17 | * @return TypeCode |
||
| 18 | */ |
||
| 19 | public function getTypeCode() |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Checks this type (Null) is compatible with another type |
||
| 26 | * Note: implementation of IType::isCompatibleWith |
||
| 27 | * |
||
| 28 | * @param IType $type Type to check compatibility |
||
| 29 | * |
||
| 30 | * @return boolean |
||
| 31 | */ |
||
| 32 | public function isCompatibleWith(IType $type) |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Validate a value in Astoria uri is in a format for this type |
||
| 39 | * Note: implementation of IType::validate |
||
| 40 | * |
||
| 41 | * @param string $value The value to validate |
||
| 42 | * @param string &$outValue The stripped form of $value that can |
||
| 43 | * be used in PHP expressions |
||
| 44 | * |
||
| 45 | * @return boolean |
||
| 46 | */ |
||
| 47 | View Code Duplication | public function validate($value, &$outValue) |
|
| 56 | |||
| 57 | /** |
||
| 58 | * Gets full name of this type in EDM namespace |
||
| 59 | * Note: implementation of IType::getFullTypeName |
||
| 60 | * |
||
| 61 | * @return string |
||
| 62 | */ |
||
| 63 | public function getFullTypeName() |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Converts the given string value to null type. |
||
| 70 | * |
||
| 71 | * @param string $stringValue value to convert |
||
| 72 | * |
||
| 73 | * @return string |
||
| 74 | */ |
||
| 75 | public function convert($stringValue) |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Convert the given value to a form that can be used in OData uri. |
||
| 86 | * |
||
| 87 | * @param mixed $value value to convert |
||
| 88 | * |
||
| 89 | * @return void |
||
| 90 | * |
||
| 91 | * @throws NotImplementedException |
||
| 92 | */ |
||
| 93 | public function convertToOData($value) |
||
| 97 | } |
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.