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 WP_Http_Encoding { |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Compress raw string using the deflate format. |
||
| 21 | * |
||
| 22 | * Supports the RFC 1951 standard. |
||
| 23 | * |
||
| 24 | * @since 2.8.0 |
||
| 25 | * |
||
| 26 | * @static |
||
| 27 | * |
||
| 28 | * @param string $raw String to compress. |
||
| 29 | * @param int $level Optional, default is 9. Compression level, 9 is highest. |
||
| 30 | * @param string $supports Optional, not used. When implemented it will choose the right compression based on what the server supports. |
||
| 31 | * @return string|false False on failure. |
||
| 32 | */ |
||
| 33 | public static function compress( $raw, $level = 9, $supports = null ) { |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Decompression of deflated string. |
||
| 39 | * |
||
| 40 | * Will attempt to decompress using the RFC 1950 standard, and if that fails |
||
| 41 | * then the RFC 1951 standard deflate will be attempted. Finally, the RFC |
||
| 42 | * 1952 standard gzip decode will be attempted. If all fail, then the |
||
| 43 | * original compressed string will be returned. |
||
| 44 | * |
||
| 45 | * @since 2.8.0 |
||
| 46 | * |
||
| 47 | * @static |
||
| 48 | * |
||
| 49 | * @param string $compressed String to decompress. |
||
| 50 | * @param int $length The optional length of the compressed data. |
||
| 51 | * @return string|bool False on failure. |
||
| 52 | */ |
||
| 53 | public static function decompress( $compressed, $length = null ) { |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Decompression of deflated string while staying compatible with the majority of servers. |
||
| 79 | * |
||
| 80 | * Certain Servers will return deflated data with headers which PHP's gzinflate() |
||
| 81 | * function cannot handle out of the box. The following function has been created from |
||
| 82 | * various snippets on the gzinflate() PHP documentation. |
||
| 83 | * |
||
| 84 | * Warning: Magic numbers within. Due to the potential different formats that the compressed |
||
| 85 | * data may be returned in, some "magic offsets" are needed to ensure proper decompression |
||
| 86 | * takes place. For a simple progmatic way to determine the magic offset in use, see: |
||
| 87 | * https://core.trac.wordpress.org/ticket/18273 |
||
| 88 | * |
||
| 89 | * @since 2.8.1 |
||
| 90 | * @link https://core.trac.wordpress.org/ticket/18273 |
||
| 91 | * @link https://secure.php.net/manual/en/function.gzinflate.php#70875 |
||
| 92 | * @link https://secure.php.net/manual/en/function.gzinflate.php#77336 |
||
| 93 | * |
||
| 94 | * @static |
||
| 95 | * |
||
| 96 | * @param string $gzData String to decompress. |
||
| 97 | * @return string|bool False on failure. |
||
| 98 | */ |
||
| 99 | public static function compatible_gzinflate($gzData) { |
||
| 129 | |||
| 130 | /** |
||
| 131 | * What encoding types to accept and their priority values. |
||
| 132 | * |
||
| 133 | * @since 2.8.0 |
||
| 134 | * |
||
| 135 | * @static |
||
| 136 | * |
||
| 137 | * @param string $url |
||
| 138 | * @param array $args |
||
| 139 | * @return string Types of encoding to accept. |
||
| 140 | */ |
||
| 141 | public static function accept_encoding( $url, $args ) { |
||
| 177 | |||
| 178 | /** |
||
| 179 | * What encoding the content used when it was compressed to send in the headers. |
||
| 180 | * |
||
| 181 | * @since 2.8.0 |
||
| 182 | * |
||
| 183 | * @static |
||
| 184 | * |
||
| 185 | * @return string Content-Encoding string to send in the header. |
||
| 186 | */ |
||
| 187 | public static function content_encoding() { |
||
| 190 | |||
| 191 | /** |
||
| 192 | * Whether the content be decoded based on the headers. |
||
| 193 | * |
||
| 194 | * @since 2.8.0 |
||
| 195 | * |
||
| 196 | * @static |
||
| 197 | * |
||
| 198 | * @param array|string $headers All of the available headers. |
||
| 199 | * @return bool |
||
| 200 | */ |
||
| 201 | public static function should_decode($headers) { |
||
| 211 | |||
| 212 | /** |
||
| 213 | * Whether decompression and compression are supported by the PHP version. |
||
| 214 | * |
||
| 215 | * Each function is tested instead of checking for the zlib extension, to |
||
| 216 | * ensure that the functions all exist in the PHP version and aren't |
||
| 217 | * disabled. |
||
| 218 | * |
||
| 219 | * @since 2.8.0 |
||
| 220 | * |
||
| 221 | * @static |
||
| 222 | * |
||
| 223 | * @return bool |
||
| 224 | */ |
||
| 225 | public static function is_available() { |
||
| 228 | } |
||
| 229 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.