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 | public $attributes; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * DatabaseModule constructor. |
||
| 16 | * |
||
| 17 | * @inheritDoc |
||
| 18 | */ |
||
| 19 | public function __construct(Container $app, string $name, $path) |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @return ModuleEntity |
||
| 27 | */ |
||
| 28 | public function getModel() |
||
| 32 | |||
| 33 | private function loadAttributes() |
||
| 59 | |||
| 60 | public function getAttributes() |
||
| 64 | |||
| 65 | public function setAttributes($attributes) |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Get a specific data from json file by given the key. |
||
| 72 | * |
||
| 73 | * @param string $key |
||
| 74 | * @param null $default |
||
| 75 | * |
||
| 76 | * @return mixed |
||
| 77 | */ |
||
| 78 | public function get(string $key, $default = null) |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Determine whether the given status same with the current module status. |
||
| 85 | * |
||
| 86 | * @param bool $status |
||
| 87 | * |
||
| 88 | * @return bool |
||
| 89 | */ |
||
| 90 | public function isStatus(bool $status): bool |
||
| 94 | |||
| 95 | /** |
||
| 96 | * Determine whether the current module activated. |
||
| 97 | * |
||
| 98 | * @return bool |
||
| 99 | */ |
||
| 100 | public function isEnabled(): bool |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Determine whether the current module not disabled. |
||
| 107 | * |
||
| 108 | * @return bool |
||
| 109 | */ |
||
| 110 | public function isDisabled(): bool |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Set active state for current module. |
||
| 117 | * |
||
| 118 | * @param bool $active |
||
| 119 | * |
||
| 120 | * @return void |
||
| 121 | */ |
||
| 122 | public function setActive(bool $active): void |
||
| 127 | |||
| 128 | /** |
||
| 129 | * Disable the current module. |
||
| 130 | */ |
||
| 131 | View Code Duplication | public function disable(): void |
|
| 140 | |||
| 141 | /** |
||
| 142 | * Enable the current module. |
||
| 143 | */ |
||
| 144 | View Code Duplication | public function enable(): void |
|
| 153 | |||
| 154 | /** |
||
| 155 | * Delete the current module. |
||
| 156 | * |
||
| 157 | * @return bool |
||
| 158 | * @throws Exception |
||
| 159 | */ |
||
| 160 | public function delete(): bool |
||
| 170 | |||
| 171 | public function getVersion() |
||
| 175 | } |
||
| 176 |