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 RestApiRequests extends Route |
||
| 17 | { |
||
| 18 | |||
| 19 | /** |
||
| 20 | * returns true if the current request matches this route |
||
| 21 | * |
||
| 22 | * @return bool |
||
| 23 | * @since $VID:$ |
||
| 24 | */ |
||
| 25 | public function matchesCurrentRequest() |
||
| 29 | |||
| 30 | |||
| 31 | /** |
||
| 32 | * @since $VID:$ |
||
| 33 | */ |
||
| 34 | View Code Duplication | protected function registerDependencies() |
|
| 35 | { |
||
| 36 | $this->dependency_map->registerDependencies( |
||
| 37 | 'EventEspresso\core\libraries\rest_api\CalculatedModelFields', |
||
| 38 | [ |
||
| 39 | 'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => EE_Dependency_Map::load_from_cache |
||
| 40 | ] |
||
| 41 | ); |
||
| 42 | $this->dependency_map->registerDependencies( |
||
| 43 | 'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory', |
||
| 44 | ['EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache] |
||
| 45 | ); |
||
| 46 | $this->dependency_map->registerDependencies( |
||
| 47 | 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
||
| 48 | ['EventEspresso\core\libraries\rest_api\CalculatedModelFields' => EE_Dependency_Map::load_from_cache] |
||
| 49 | ); |
||
| 50 | $this->dependency_map->registerDependencies( |
||
| 51 | 'EventEspresso\core\libraries\rest_api\calculations\Datetime', |
||
| 52 | [ |
||
| 53 | 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
||
| 54 | 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
||
| 55 | ] |
||
| 56 | ); |
||
| 57 | $this->dependency_map->registerDependencies( |
||
| 58 | 'EventEspresso\core\libraries\rest_api\calculations\Event', |
||
| 59 | [ |
||
| 60 | 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
||
| 61 | 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
||
| 62 | ] |
||
| 63 | ); |
||
| 64 | $this->dependency_map->registerDependencies( |
||
| 65 | 'EventEspresso\core\libraries\rest_api\calculations\Registration', |
||
| 66 | ['EEM_Registration' => EE_Dependency_Map::load_from_cache] |
||
| 67 | ); |
||
| 68 | } |
||
| 69 | |||
| 70 | |||
| 71 | /** |
||
| 72 | * implements logic required to run during request |
||
| 73 | * |
||
| 74 | * @return bool |
||
| 75 | * @since $VID:$ |
||
| 76 | */ |
||
| 77 | protected function requestHandler() |
||
| 82 | } |
||
| 83 |