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 |
||
17 | class WordPressPluginsPage extends Route |
||
18 | { |
||
19 | |||
20 | /** |
||
21 | * returns true if the current request matches this route |
||
22 | * |
||
23 | * @return bool |
||
24 | * @since $VID:$ |
||
25 | */ |
||
26 | public function matchesCurrentRequest() |
||
27 | { |
||
28 | global $pagenow; |
||
29 | return $this->request->isAdmin() && $pagenow && $pagenow === 'plugins.php'; |
||
30 | } |
||
31 | |||
32 | |||
33 | /** |
||
34 | * @since $VID:$ |
||
35 | */ |
||
36 | View Code Duplication | protected function registerDependencies() |
|
37 | { |
||
38 | $this->dependency_map->registerDependencies( |
||
39 | 'EventEspresso\core\domain\services\assets\WordpressPluginsPageAssetManager', |
||
40 | [ |
||
41 | 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
||
42 | 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
||
43 | 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
||
44 | 'EventEspresso\core\domain\services\admin\ExitModal' => EE_Dependency_Map::load_from_cache, |
||
45 | ] |
||
46 | ); |
||
47 | $this->dependency_map->registerDependencies( |
||
48 | 'EventEspresso\core\domain\services\admin\ExitModal', |
||
49 | ['EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache] |
||
50 | ); |
||
51 | $this->dependency_map->registerDependencies( |
||
52 | 'EventEspresso\core\domain\services\admin\PluginUpsells', |
||
53 | ['EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache] |
||
54 | ); |
||
55 | } |
||
56 | |||
57 | |||
58 | /** |
||
59 | * implements logic required to run during request |
||
60 | * |
||
61 | * @return bool |
||
62 | * @since $VID:$ |
||
63 | */ |
||
64 | protected function requestHandler() |
||
72 | } |
||
73 |