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 |
||
| 17 | class Walker_Comment extends Walker { |
||
| 18 | |||
| 19 | /** |
||
| 20 | * What the class handles. |
||
| 21 | * |
||
| 22 | * @since 2.7.0 |
||
| 23 | * @access public |
||
| 24 | * @var string |
||
| 25 | * |
||
| 26 | * @see Walker::$tree_type |
||
| 27 | */ |
||
| 28 | public $tree_type = 'comment'; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Database fields to use. |
||
| 32 | * |
||
| 33 | * @since 2.7.0 |
||
| 34 | * @access public |
||
| 35 | * @var array |
||
| 36 | * |
||
| 37 | * @see Walker::$db_fields |
||
| 38 | * @todo Decouple this |
||
| 39 | */ |
||
| 40 | public $db_fields = array ('parent' => 'comment_parent', 'id' => 'comment_ID'); |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Starts the list before the elements are added. |
||
| 44 | * |
||
| 45 | * @since 2.7.0 |
||
| 46 | * @access public |
||
| 47 | * |
||
| 48 | * @see Walker::start_lvl() |
||
| 49 | * @global int $comment_depth |
||
| 50 | * |
||
| 51 | * @param string $output Passed by reference. Used to append additional content. |
||
| 52 | * @param int $depth Optional. Depth of the current comment. Default 0. |
||
| 53 | * @param array $args Optional. Uses 'style' argument for type of HTML list. Default empty array. |
||
| 54 | */ |
||
| 55 | View Code Duplication | public function start_lvl( &$output, $depth = 0, $args = array() ) { |
|
| 70 | |||
| 71 | /** |
||
| 72 | * Ends the list of items after the elements are added. |
||
| 73 | * |
||
| 74 | * @since 2.7.0 |
||
| 75 | * @access public |
||
| 76 | * |
||
| 77 | * @see Walker::end_lvl() |
||
| 78 | * @global int $comment_depth |
||
| 79 | * |
||
| 80 | * @param string $output Passed by reference. Used to append additional content. |
||
| 81 | * @param int $depth Optional. Depth of the current comment. Default 0. |
||
| 82 | * @param array $args Optional. Will only append content if style argument value is 'ol' or 'ul'. |
||
| 83 | * Default empty array. |
||
| 84 | */ |
||
| 85 | View Code Duplication | public function end_lvl( &$output, $depth = 0, $args = array() ) { |
|
| 100 | |||
| 101 | /** |
||
| 102 | * Traverses elements to create list from elements. |
||
| 103 | * |
||
| 104 | * This function is designed to enhance Walker::display_element() to |
||
| 105 | * display children of higher nesting levels than selected inline on |
||
| 106 | * the highest depth level displayed. This prevents them being orphaned |
||
| 107 | * at the end of the comment list. |
||
| 108 | * |
||
| 109 | * Example: max_depth = 2, with 5 levels of nested content. |
||
| 110 | * 1 |
||
| 111 | * 1.1 |
||
| 112 | * 1.1.1 |
||
| 113 | * 1.1.1.1 |
||
| 114 | * 1.1.1.1.1 |
||
| 115 | * 1.1.2 |
||
| 116 | * 1.1.2.1 |
||
| 117 | * 2 |
||
| 118 | * 2.2 |
||
| 119 | * |
||
| 120 | * @since 2.7.0 |
||
| 121 | * @access public |
||
| 122 | * |
||
| 123 | * @see Walker::display_element() |
||
| 124 | * @see wp_list_comments() |
||
| 125 | * |
||
| 126 | * @param WP_Comment $element Comment data object. |
||
| 127 | * @param array $children_elements List of elements to continue traversing. Passed by reference. |
||
| 128 | * @param int $max_depth Max depth to traverse. |
||
| 129 | * @param int $depth Depth of the current element. |
||
| 130 | * @param array $args An array of arguments. |
||
| 131 | * @param string $output Used to append additional content. Passed by reference. |
||
| 132 | */ |
||
| 133 | public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) { |
||
| 155 | |||
| 156 | /** |
||
| 157 | * Starts the element output. |
||
| 158 | * |
||
| 159 | * @since 2.7.0 |
||
| 160 | * @access public |
||
| 161 | * |
||
| 162 | * @see Walker::start_el() |
||
| 163 | * @see wp_list_comments() |
||
| 164 | * @global int $comment_depth |
||
| 165 | * @global WP_Comment $comment |
||
| 166 | * |
||
| 167 | * @param string $output Used to append additional content. Passed by reference. |
||
| 168 | * @param WP_Comment $comment Comment data object. |
||
| 169 | * @param int $depth Optional. Depth of the current comment in reference to parents. Default 0. |
||
| 170 | * @param array $args Optional. An array of arguments. Default empty array. |
||
| 171 | * @param int $id Optional. ID of the current comment. Default 0 (unused). |
||
| 172 | */ |
||
| 173 | public function start_el( &$output, $comment, $depth = 0, $args = array(), $id = 0 ) { |
||
| 199 | |||
| 200 | /** |
||
| 201 | * Ends the element output, if needed. |
||
| 202 | * |
||
| 203 | * @since 2.7.0 |
||
| 204 | * @access public |
||
| 205 | * |
||
| 206 | * @see Walker::end_el() |
||
| 207 | * @see wp_list_comments() |
||
| 208 | * |
||
| 209 | * @param string $output Used to append additional content. Passed by reference. |
||
| 210 | * @param WP_Comment $comment The current comment object. Default current comment. |
||
| 211 | * @param int $depth Optional. Depth of the current comment. Default 0. |
||
| 212 | * @param array $args Optional. An array of arguments. Default empty array. |
||
| 213 | */ |
||
| 214 | public function end_el( &$output, $comment, $depth = 0, $args = array() ) { |
||
| 226 | |||
| 227 | /** |
||
| 228 | * Outputs a pingback comment. |
||
| 229 | * |
||
| 230 | * @since 3.6.0 |
||
| 231 | * @access protected |
||
| 232 | * |
||
| 233 | * @see wp_list_comments() |
||
| 234 | * |
||
| 235 | * @param WP_Comment $comment The comment object. |
||
| 236 | * @param int $depth Depth of the current comment. |
||
| 237 | * @param array $args An array of arguments. |
||
| 238 | */ |
||
| 239 | protected function ping( $comment, $depth, $args ) { |
||
| 248 | |||
| 249 | /** |
||
| 250 | * Outputs a single comment. |
||
| 251 | * |
||
| 252 | * @since 3.6.0 |
||
| 253 | * @access protected |
||
| 254 | * |
||
| 255 | * @see wp_list_comments() |
||
| 256 | * |
||
| 257 | * @param WP_Comment $comment Comment to display. |
||
| 258 | * @param int $depth Depth of the current comment. |
||
| 259 | * @param array $args An array of arguments. |
||
| 260 | */ |
||
| 261 | protected function comment( $comment, $depth, $args ) { |
||
| 312 | |||
| 313 | /** |
||
| 314 | * Outputs a comment in the HTML5 format. |
||
| 315 | * |
||
| 316 | * @since 3.6.0 |
||
| 317 | * @access protected |
||
| 318 | * |
||
| 319 | * @see wp_list_comments() |
||
| 320 | * |
||
| 321 | * @param WP_Comment $comment Comment to display. |
||
| 322 | * @param int $depth Depth of the current comment. |
||
| 323 | * @param array $args An array of arguments. |
||
| 324 | */ |
||
| 325 | protected function html5_comment( $comment, $depth, $args ) { |
||
| 374 | } |
||
| 375 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.