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 |
||
| 7 | class Jetpack_WordAds_Shortcode { |
||
| 8 | |||
| 9 | private $scripts_and_style_included = false; |
||
|
|
|||
| 10 | |||
| 11 | function __construct() { |
||
| 14 | |||
| 15 | /** |
||
| 16 | * Register our shortcode and enqueue necessary files. |
||
| 17 | */ |
||
| 18 | function action_init() { |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Add hooks according to screen. |
||
| 29 | * |
||
| 30 | * @param WP_Screen $screen Data about current screen. |
||
| 31 | */ |
||
| 32 | public static function add_hooks( $screen ) { |
||
| 38 | |||
| 39 | public static function mce_external_plugins( $plugin_array ) { |
||
| 46 | |||
| 47 | /** |
||
| 48 | * WordPress Shortcode Editor View JS Code |
||
| 49 | */ |
||
| 50 | public static function handle_editor_view_js() { |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Our [wordad] shortcode. |
||
| 72 | * Prints a WordAds Ad. |
||
| 73 | * |
||
| 74 | * @param array $atts Array of shortcode attributes. |
||
| 75 | * @param string $content Post content. |
||
| 76 | * |
||
| 77 | * @return string HTML for WordAds shortcode. |
||
| 78 | */ |
||
| 79 | static function wordads_shortcode( $atts, $content = '' ) { |
||
| 87 | |||
| 88 | /** |
||
| 89 | * The shortcode output |
||
| 90 | * |
||
| 91 | * @param array $atts Array of shortcode attributes. |
||
| 92 | * @param string $content Post content. |
||
| 93 | * |
||
| 94 | * @return string HTML output |
||
| 95 | */ |
||
| 96 | static function wordads_shortcode_html( $atts, $content = '' ) { |
||
| 111 | |||
| 112 | public static function admin_head() { |
||
| 116 | |||
| 117 | View Code Duplication | public static function wordads_media_button() { |
|
| 128 | } |
||
| 129 | |||
| 132 |
This check marks private properties in classes that are never used. Those properties can be removed.