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 |
||
| 30 | class InfoChecker extends BasicEmitter { |
||
| 31 | |||
| 32 | /** @var string[] */ |
||
| 33 | private $shippedApps; |
||
| 34 | |||
| 35 | /** @var string[] */ |
||
| 36 | private $alwaysEnabled; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @param string $appId |
||
| 40 | * @return array |
||
| 41 | * @throws \RuntimeException |
||
| 42 | */ |
||
| 43 | public function analyse($appId): array { |
||
| 75 | |||
| 76 | /** |
||
| 77 | * This is a copy of \OC\App\AppManager::isShipped(), keep both in sync. |
||
| 78 | * This method is copied, so the code checker works even when Nextcloud is |
||
| 79 | * not installed yet. The AppManager requires a database connection, which |
||
| 80 | * fails in that case. |
||
| 81 | * |
||
| 82 | * @param string $appId |
||
| 83 | * @return bool |
||
| 84 | * @throws \Exception |
||
| 85 | */ |
||
| 86 | protected function isShipped(string $appId): bool { |
||
| 90 | |||
| 91 | /** |
||
| 92 | * This is a copy of \OC\App\AppManager::loadShippedJson(), keep both in sync |
||
| 93 | * This method is copied, so the code checker works even when Nextcloud is |
||
| 94 | * not installed yet. The AppManager requires a database connection, which |
||
| 95 | * fails in that case. |
||
| 96 | * |
||
| 97 | * @throws \Exception |
||
| 98 | */ |
||
| 99 | View Code Duplication | protected function loadShippedJson() { |
|
| 110 | } |
||
| 111 |