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 |
||
| 12 | class Give_Frontend { |
||
|
|
|||
| 13 | /** |
||
| 14 | * Instance. |
||
| 15 | * |
||
| 16 | * @since 2.4.0 |
||
| 17 | * @access private |
||
| 18 | * @var |
||
| 19 | */ |
||
| 20 | static private $instance; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Singleton pattern. |
||
| 24 | * |
||
| 25 | * @since 2.4.0 |
||
| 26 | * @access private |
||
| 27 | */ |
||
| 28 | private function __construct() { |
||
| 30 | |||
| 31 | |||
| 32 | /** |
||
| 33 | * Get instance. |
||
| 34 | * |
||
| 35 | * @since 2.4.0 |
||
| 36 | * @access public |
||
| 37 | * @return Give_Frontend |
||
| 38 | */ |
||
| 39 | View Code Duplication | public static function get_instance() { |
|
| 47 | |||
| 48 | /** |
||
| 49 | * Setup Admin |
||
| 50 | * |
||
| 51 | * @sinve 2.4.0 |
||
| 52 | * @access private |
||
| 53 | */ |
||
| 54 | private function setup() { |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Load core file |
||
| 62 | * |
||
| 63 | * @since 2.4.0 |
||
| 64 | * @access private |
||
| 65 | */ |
||
| 66 | private function admin_loading() { |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Backward compatibility GIVE_VERSION < 2.4.0 |
||
| 73 | * |
||
| 74 | * @since 2.4.0 |
||
| 75 | * @ccess public |
||
| 76 | * |
||
| 77 | * @param Give $give |
||
| 78 | */ |
||
| 79 | public function bc_240( $give ) { |
||
| 83 | } |
||
| 84 | |||
| 86 |