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 |
||
| 32 | class PaletteImage extends Image |
||
| 33 | { |
||
| 34 | /** |
||
| 35 | * Create a palette image |
||
| 36 | * |
||
| 37 | * @param int $width |
||
| 38 | * @param int $height |
||
| 39 | * @return \WideImage\PaletteImage |
||
| 40 | */ |
||
| 41 | View Code Duplication | public static function create($width, $height) |
|
| 49 | |||
| 50 | public function doCreate($width, $height) |
||
| 54 | |||
| 55 | /** |
||
| 56 | * (non-PHPdoc) |
||
| 57 | * @see \WideImage\Image#isTrueColor() |
||
| 58 | */ |
||
| 59 | public function isTrueColor() |
||
| 63 | |||
| 64 | /** |
||
| 65 | * (non-PHPdoc) |
||
| 66 | * @see \WideImage\Image#asPalette($nColors, $dither, $matchPalette) |
||
| 67 | */ |
||
| 68 | public function asPalette($nColors = 255, $dither = null, $matchPalette = true) |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Returns a copy of the image |
||
| 75 | * |
||
| 76 | * @param $trueColor True if the new image should be truecolor |
||
| 77 | * @return \WideImage\Image |
||
| 78 | */ |
||
| 79 | protected function copyAsNew($trueColor = false) |
||
| 105 | |||
| 106 | /** |
||
| 107 | * (non-PHPdoc) |
||
| 108 | * @see \WideImage\Image#asTrueColor() |
||
| 109 | */ |
||
| 110 | public function asTrueColor() |
||
| 126 | |||
| 127 | /** |
||
| 128 | * (non-PHPdoc) |
||
| 129 | * @see \WideImage\Image#getChannels() |
||
| 130 | */ |
||
| 131 | View Code Duplication | public function getChannels() |
|
| 141 | |||
| 142 | /** |
||
| 143 | * (non-PHPdoc) |
||
| 144 | * @see \WideImage\Image#copyNoAlpha() |
||
| 145 | */ |
||
| 146 | public function copyNoAlpha() |
||
| 150 | } |
||
| 151 |
This check looks for accesses to local static members using the fully qualified name instead of
self::.While this is perfectly valid, the fully qualified name of
Certificate::TRIPLEDES_CBCcould just as well be replaced byself::TRIPLEDES_CBC. Referencing local members withself::assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.