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 |
||
| 18 | class Offline |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * Summary of check |
||
| 22 | * @param bool $external External interface |
||
| 23 | * @deprecated Do checking within the entry point. |
||
| 24 | */ |
||
| 25 | public static function check($external) |
||
| 26 | { |
||
| 27 | global $smarty, $dontUseDb, $dontUseDbCulprit, $dontUseDbReason; |
||
| 28 | |||
| 29 | if ($dontUseDb) { |
||
| 30 | if ($external) { |
||
| 31 | $smarty->display("offline/external.tpl"); |
||
| 32 | } |
||
| 33 | else { |
||
| 34 | $smarty->assign("dontUseDbCulprit", $dontUseDbCulprit); |
||
| 35 | $smarty->assign("dontUseDbReason", $dontUseDbReason); |
||
| 36 | $smarty->assign("alerts", array()); |
||
| 37 | $smarty->display("offline/internal.tpl"); |
||
| 38 | } |
||
| 39 | |||
| 40 | die(); |
||
|
|
|||
| 41 | } |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Determines if the tool is offline |
||
| 46 | * @return bool |
||
| 47 | */ |
||
| 48 | public static function isOffline() |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Gets the offline message |
||
| 57 | * @param bool $external |
||
| 58 | * @return string |
||
| 59 | */ |
||
| 60 | public static function getOfflineMessage($external) |
||
| 72 | } |
||
| 73 | } |
||
| 74 | } |
||
| 75 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.