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 | * DatabaseModule constructor. |
||
| 22 | * |
||
| 23 | * @inheritDoc |
||
| 24 | */ |
||
| 25 | public function __construct(Container $app, string $name, $path) |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @return ModuleEntity |
||
| 33 | */ |
||
| 34 | public function getModel() |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Load attributes. |
||
| 41 | * |
||
| 42 | * @return mixed |
||
| 43 | * @throws Exception |
||
| 44 | */ |
||
| 45 | private function loadAttributes() |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Get attributes. |
||
| 74 | * |
||
| 75 | * @return array |
||
| 76 | */ |
||
| 77 | public function getAttributes() |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Set attributes. |
||
| 84 | * |
||
| 85 | * @param array $attributes |
||
| 86 | */ |
||
| 87 | public function setAttributes($attributes) |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Get a specific data from json file by given the key. |
||
| 94 | * |
||
| 95 | * @param string $key |
||
| 96 | * @param null $default |
||
| 97 | * |
||
| 98 | * @return mixed |
||
| 99 | */ |
||
| 100 | public function get(string $key, $default = null) |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Determine whether the given status same with the current module status. |
||
| 107 | * |
||
| 108 | * @param bool $status |
||
| 109 | * |
||
| 110 | * @return bool |
||
| 111 | */ |
||
| 112 | public function isStatus(bool $status): bool |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Determine whether the current module activated. |
||
| 119 | * |
||
| 120 | * @return bool |
||
| 121 | */ |
||
| 122 | public function isEnabled(): bool |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Determine whether the current module not disabled. |
||
| 129 | * |
||
| 130 | * @return bool |
||
| 131 | */ |
||
| 132 | public function isDisabled(): bool |
||
| 136 | |||
| 137 | /** |
||
| 138 | * Set active state for current module. |
||
| 139 | * |
||
| 140 | * @param bool $active |
||
| 141 | * |
||
| 142 | * @return void |
||
| 143 | */ |
||
| 144 | public function setActive(bool $active): void |
||
| 149 | |||
| 150 | /** |
||
| 151 | * Disable the current module. |
||
| 152 | */ |
||
| 153 | View Code Duplication | public function disable(): void |
|
| 162 | |||
| 163 | /** |
||
| 164 | * Enable the current module. |
||
| 165 | */ |
||
| 166 | View Code Duplication | public function enable(): void |
|
| 175 | |||
| 176 | /** |
||
| 177 | * Delete the current module. |
||
| 178 | * |
||
| 179 | * @return bool |
||
| 180 | * @throws Exception |
||
| 181 | */ |
||
| 182 | public function delete(): bool |
||
| 192 | |||
| 193 | /** |
||
| 194 | * @return mixed|null |
||
| 195 | */ |
||
| 196 | public function getVersion() |
||
| 200 | |||
| 201 | public function update(Updater $updater) |
||
| 224 | } |
||
| 225 |