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 |
||
| 14 | abstract class Jetpack_Sitemap_Buffer_Fallback extends Jetpack_Sitemap_Buffer { |
||
| 15 | |||
| 16 | /** |
||
| 17 | * The buffer contents. |
||
| 18 | * |
||
| 19 | * @access protected |
||
| 20 | * @since 5.3.0 |
||
| 21 | * @var string The buffer contents. |
||
| 22 | */ |
||
| 23 | protected $buffer; |
||
| 24 | |||
| 25 | View Code Duplication | public function __construct( $item_limit, $byte_limit, $time = '1970-01-01 00:00:00' ) { |
|
| 35 | |||
| 36 | /** |
||
| 37 | * Append an item to the buffer, if there is room for it, |
||
| 38 | * and set is_empty_flag to false. If there is no room, |
||
| 39 | * we set is_full_flag to true. If $item is null, |
||
| 40 | * don't do anything and report success. |
||
| 41 | * |
||
| 42 | * @since 5.3.0 |
||
| 43 | * |
||
| 44 | * @param array $array The item to be added. |
||
| 45 | * |
||
| 46 | * @return bool True if the append succeeded, False if not. |
||
| 47 | */ |
||
| 48 | public function append( $array ) { |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Detect whether the buffer is empty. |
||
| 76 | * |
||
| 77 | * @since 5.3.0 |
||
| 78 | * |
||
| 79 | * @return bool True if the buffer is empty, false otherwise. |
||
| 80 | */ |
||
| 81 | public function is_empty() { |
||
| 84 | |||
| 85 | /** |
||
| 86 | * Retrieve the contents of the buffer. |
||
| 87 | * |
||
| 88 | * @since 5.3.0 |
||
| 89 | * |
||
| 90 | * @return string The contents of the buffer (with the footer included). |
||
| 91 | */ |
||
| 92 | public function contents() { |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Legacy implementation of array to XML conversion without using DOMDocument. |
||
| 100 | * |
||
| 101 | * @param Array $array |
||
| 102 | * @return String $result |
||
| 103 | */ |
||
| 104 | public function array_to_xml_string( $array, $parent = null, $root = null ) { |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Render an associative array of XML attribute key/value pairs. |
||
| 127 | * |
||
| 128 | * @access public |
||
| 129 | * @since 5.3.0 |
||
| 130 | * |
||
| 131 | * @param array $array Key/value array of attributes. |
||
| 132 | * |
||
| 133 | * @return string The rendered attribute string. |
||
| 134 | */ |
||
| 135 | public static function array_to_xml_attr_string( $array ) { |
||
| 145 | |||
| 146 | } |
||
| 147 |