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 |
||
| 15 | View Code Duplication | final class WordPoints_Module_APIs extends WordPoints_Container_Static { |
|
|
|
|||
| 16 | |||
| 17 | /** |
||
| 18 | * @since 1.0.0 |
||
| 19 | */ |
||
| 20 | protected static $instance; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Initialize the container. |
||
| 24 | * |
||
| 25 | * This function must be called before the container can be used. |
||
| 26 | * |
||
| 27 | * @since 1.0.0 |
||
| 28 | * |
||
| 29 | * @return bool True if the container was initialized, false if it was already. |
||
| 30 | */ |
||
| 31 | public static function init() { |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @since 1.0.0 |
||
| 47 | * |
||
| 48 | * @see WordPoints_Container::_add() |
||
| 49 | */ |
||
| 50 | public static function register( $slug, $item, $class = null ) { |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @since 1.0.0 |
||
| 56 | * |
||
| 57 | * @see WordPoints_Container::_remove() |
||
| 58 | */ |
||
| 59 | public static function deregister( $slug ) { |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @since 1.0.0 |
||
| 65 | * |
||
| 66 | * @see WordPoints_Container::_contains() |
||
| 67 | */ |
||
| 68 | public static function is_registered( $slug ) { |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @since 1.0.0 |
||
| 74 | * |
||
| 75 | * @see WordPoints_Container::_get() |
||
| 76 | * |
||
| 77 | * @return WordPoints_Module_API[]|WordPoints_Module_API |
||
| 78 | */ |
||
| 79 | public static function get( $slug = null ) { |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Call the action to register all of the installed APIs. |
||
| 85 | * |
||
| 86 | * @since 1.0.0 |
||
| 87 | */ |
||
| 88 | private static function register_apis() { |
||
| 97 | } |
||
| 98 | add_action( 'admin_init', 'WordPoints_Module_APIs::init' ); |
||
| 200 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.