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 Base |
||
| 17 | { |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @param $required_permission |
||
| 21 | * @param $attempted_calculation |
||
| 22 | * @throws RestException |
||
| 23 | */ |
||
| 24 | protected function verifyCurrentUserCan($required_permission, $attempted_calculation) |
||
| 43 | |||
| 44 | |||
| 45 | /** |
||
| 46 | * Gets the name of the resource of the called class |
||
| 47 | * |
||
| 48 | * @return string |
||
| 49 | */ |
||
| 50 | public function getResourceName() |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Returns an array to be used for the schema for the calculated fields. |
||
| 57 | * @since $VID:$ |
||
| 58 | * @return array keys are calculated field names (eg "optimum_sales_at_start") values are arrays { |
||
| 59 | * @type string $description |
||
| 60 | * @type string $type, eg "string", "int", "boolean", "object", "array", etc |
||
| 61 | * } |
||
| 62 | */ |
||
| 63 | public function schemaForCalculations() |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Returns the json schema for the given calculation index. |
||
| 70 | * |
||
| 71 | * @since $VID:$ |
||
| 72 | * @param $calculation_index |
||
| 73 | * @return array |
||
| 74 | */ |
||
| 75 | public function schemaForCalculation($calculation_index) |
||
| 80 | } |
||
| 81 |