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 |
||
| 35 | class XCFHandler extends BitmapHandler { |
||
| 36 | /** |
||
| 37 | * @param File $file |
||
| 38 | * @return bool |
||
| 39 | */ |
||
| 40 | public function mustRender( $file ) { |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Render files as PNG |
||
| 46 | * |
||
| 47 | * @param string $ext |
||
| 48 | * @param string $mime |
||
| 49 | * @param array $params |
||
| 50 | * @return array |
||
| 51 | */ |
||
| 52 | function getThumbType( $ext, $mime, $params = null ) { |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Get width and height from the XCF header. |
||
| 58 | * |
||
| 59 | * @param File $image |
||
| 60 | * @param string $filename |
||
| 61 | * @return array |
||
| 62 | */ |
||
| 63 | function getImageSize( $image, $filename ) { |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Metadata for a given XCF file |
||
| 84 | * |
||
| 85 | * Will return false if file magic signature is not recognized |
||
| 86 | * @author Hexmode |
||
| 87 | * @author Hashar |
||
| 88 | * |
||
| 89 | * @param string $filename Full path to a XCF file |
||
| 90 | * @return bool|array Metadata Array just like PHP getimagesize() |
||
| 91 | */ |
||
| 92 | static function getXCFMetaData( $filename ) { |
||
| 146 | |||
| 147 | /** |
||
| 148 | * Store the channel type |
||
| 149 | * |
||
| 150 | * Greyscale files need different command line options. |
||
| 151 | * |
||
| 152 | * @param File $file The image object, or false if there isn't one. |
||
| 153 | * Warning, FSFile::getPropsFromPath might pass an (object)array() instead (!) |
||
| 154 | * @param string $filename The filename |
||
| 155 | * @return string |
||
| 156 | */ |
||
| 157 | public function getMetadata( $file, $filename ) { |
||
| 184 | |||
| 185 | /** |
||
| 186 | * Should we refresh the metadata |
||
| 187 | * |
||
| 188 | * @param File $file The file object for the file in question |
||
| 189 | * @param string $metadata Serialized metadata |
||
| 190 | * @return bool One of the self::METADATA_(BAD|GOOD|COMPATIBLE) constants |
||
| 191 | */ |
||
| 192 | public function isMetadataValid( $file, $metadata ) { |
||
| 200 | |||
| 201 | /** |
||
| 202 | * Must use "im" for XCF |
||
| 203 | * |
||
| 204 | * @param string $dstPath |
||
| 205 | * @param bool $checkDstPath |
||
| 206 | * @return string |
||
| 207 | */ |
||
| 208 | protected function getScalerType( $dstPath, $checkDstPath = true ) { |
||
| 211 | |||
| 212 | /** |
||
| 213 | * Can we render this file? |
||
| 214 | * |
||
| 215 | * Image magick doesn't support indexed xcf files as of current |
||
| 216 | * writing (as of 6.8.9-3) |
||
| 217 | * @param File $file |
||
| 218 | * @return bool |
||
| 219 | */ |
||
| 220 | View Code Duplication | public function canRender( $file ) { |
|
| 229 | } |
||
| 230 |