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 |
||
| 33 | class HEIC extends Provider { |
||
| 34 | /** |
||
| 35 | * {@inheritDoc} |
||
| 36 | */ |
||
| 37 | public function getMimeType(): string { |
||
| 40 | |||
| 41 | /** |
||
| 42 | * {@inheritDoc} |
||
| 43 | */ |
||
| 44 | public function isAvailable(\OCP\Files\FileInfo $file): bool { |
||
| 47 | |||
| 48 | /** |
||
| 49 | * {@inheritDoc} |
||
| 50 | */ |
||
| 51 | View Code Duplication | public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { |
|
| 78 | |||
| 79 | /** |
||
| 80 | * Returns a preview of maxX times maxY dimensions in JPG format |
||
| 81 | * |
||
| 82 | * * The default resolution is already 72dpi, no need to change it for a bitmap output |
||
| 83 | * * It's possible to have proper colour conversion using profileimage(). |
||
| 84 | * ICC profiles are here: http://www.color.org/srgbprofiles.xalter |
||
| 85 | * * It's possible to Gamma-correct an image via gammaImage() |
||
| 86 | * |
||
| 87 | * @param string $tmpPath the location of the file to convert |
||
| 88 | * @param int $maxX |
||
| 89 | * @param int $maxY |
||
| 90 | * |
||
| 91 | * @return \Imagick |
||
| 92 | */ |
||
| 93 | View Code Duplication | private function getResizedPreview($tmpPath, $maxX, $maxY) { |
|
| 105 | |||
| 106 | /** |
||
| 107 | * Returns a resized \Imagick object |
||
| 108 | * |
||
| 109 | * If you want to know more on the various methods available to resize an |
||
| 110 | * image, check out this link : @link https://stackoverflow.com/questions/8517304/what-the-difference-of-sample-resample-scale-resize-adaptive-resize-thumbnail-im |
||
| 111 | * |
||
| 112 | * @param \Imagick $bp |
||
| 113 | * @param int $maxX |
||
| 114 | * @param int $maxY |
||
| 115 | * |
||
| 116 | * @return \Imagick |
||
| 117 | */ |
||
| 118 | private function resize($bp, $maxX, $maxY) { |
||
| 139 | |||
| 140 | } |
||
| 141 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: