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 |
||
| 10 | class DatabaseModule extends Module |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @var array |
||
| 14 | */ |
||
| 15 | public $attributes; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * DatabaseModule constructor. |
||
| 19 | * |
||
| 20 | * @inheritDoc |
||
| 21 | */ |
||
| 22 | public function __construct(Container $app, string $name, $path) |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @return ModuleEntity |
||
| 30 | */ |
||
| 31 | public function getModel() |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Load attributes. |
||
| 38 | * |
||
| 39 | * @return mixed |
||
| 40 | * @throws Exception |
||
| 41 | */ |
||
| 42 | private function loadAttributes() |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Get attributes. |
||
| 71 | * |
||
| 72 | * @return array |
||
| 73 | */ |
||
| 74 | public function getAttributes() |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Set attributes. |
||
| 81 | * |
||
| 82 | * @param array $attributes |
||
| 83 | */ |
||
| 84 | public function setAttributes($attributes) |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Get a specific data from json file by given the key. |
||
| 91 | * |
||
| 92 | * @param string $key |
||
| 93 | * @param null $default |
||
| 94 | * |
||
| 95 | * @return mixed |
||
| 96 | */ |
||
| 97 | public function get(string $key, $default = null) |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Determine whether the given status same with the current module status. |
||
| 104 | * |
||
| 105 | * @param bool $status |
||
| 106 | * |
||
| 107 | * @return bool |
||
| 108 | */ |
||
| 109 | public function isStatus(bool $status): bool |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Determine whether the current module activated. |
||
| 116 | * |
||
| 117 | * @return bool |
||
| 118 | */ |
||
| 119 | public function isEnabled(): bool |
||
| 123 | |||
| 124 | /** |
||
| 125 | * Determine whether the current module not disabled. |
||
| 126 | * |
||
| 127 | * @return bool |
||
| 128 | */ |
||
| 129 | public function isDisabled(): bool |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Set active state for current module. |
||
| 136 | * |
||
| 137 | * @param bool $active |
||
| 138 | * |
||
| 139 | * @return void |
||
| 140 | */ |
||
| 141 | public function setActive(bool $active): void |
||
| 146 | |||
| 147 | /** |
||
| 148 | * Disable the current module. |
||
| 149 | */ |
||
| 150 | View Code Duplication | public function disable(): void |
|
| 159 | |||
| 160 | /** |
||
| 161 | * Enable the current module. |
||
| 162 | */ |
||
| 163 | View Code Duplication | public function enable(): void |
|
| 172 | |||
| 173 | /** |
||
| 174 | * Delete the current module. |
||
| 175 | * |
||
| 176 | * @return bool |
||
| 177 | * @throws Exception |
||
| 178 | */ |
||
| 179 | public function delete(): bool |
||
| 189 | |||
| 190 | /** |
||
| 191 | * @return mixed|null |
||
| 192 | */ |
||
| 193 | public function getVersion() |
||
| 197 | } |
||
| 198 |