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 |
||
| 13 | class DatabaseModule extends Module |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @var array |
||
| 17 | */ |
||
| 18 | public $attributes; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @return ModuleEntity |
||
| 22 | */ |
||
| 23 | public function getModel() |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Load attributes. |
||
| 30 | * |
||
| 31 | * @return mixed |
||
| 32 | * @throws Exception |
||
| 33 | */ |
||
| 34 | private function loadAttributes() |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Get attributes. |
||
| 63 | * |
||
| 64 | * @return array |
||
| 65 | */ |
||
| 66 | public function getAttributes() |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Set attributes. |
||
| 73 | * |
||
| 74 | * @param array $attributes |
||
| 75 | */ |
||
| 76 | public function setAttributes($attributes) |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Get a specific data from json file by given the key. |
||
| 83 | * |
||
| 84 | * @param string $key |
||
| 85 | * @param null $default |
||
| 86 | * |
||
| 87 | * @return mixed |
||
| 88 | */ |
||
| 89 | public function get(string $key, $default = null) |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Determine whether the given status same with the current module status. |
||
| 96 | * |
||
| 97 | * @param bool $status |
||
| 98 | * |
||
| 99 | * @return bool |
||
| 100 | */ |
||
| 101 | public function isStatus(bool $status): bool |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Determine whether the current module activated. |
||
| 108 | * |
||
| 109 | * @return bool |
||
| 110 | */ |
||
| 111 | public function isEnabled(): bool |
||
| 115 | |||
| 116 | /** |
||
| 117 | * Determine whether the current module not disabled. |
||
| 118 | * |
||
| 119 | * @return bool |
||
| 120 | */ |
||
| 121 | public function isDisabled(): bool |
||
| 125 | |||
| 126 | /** |
||
| 127 | * Set active state for current module. |
||
| 128 | * |
||
| 129 | * @param bool $active |
||
| 130 | * |
||
| 131 | * @return void |
||
| 132 | */ |
||
| 133 | public function setActive(bool $active): void |
||
| 138 | |||
| 139 | /** |
||
| 140 | * Disable the current module. |
||
| 141 | */ |
||
| 142 | View Code Duplication | public function disable(): void |
|
| 151 | |||
| 152 | /** |
||
| 153 | * Enable the current module. |
||
| 154 | */ |
||
| 155 | View Code Duplication | public function enable(): void |
|
| 164 | |||
| 165 | /** |
||
| 166 | * Delete the current module. |
||
| 167 | * |
||
| 168 | * @return bool |
||
| 169 | * @throws Exception |
||
| 170 | */ |
||
| 171 | public function delete(): bool |
||
| 181 | |||
| 182 | /** |
||
| 183 | * @return mixed|null |
||
| 184 | */ |
||
| 185 | public function getVersion() |
||
| 189 | |||
| 190 | public function update(Updater $updater) |
||
| 213 | } |
||
| 214 |