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 |
||
| 28 | class XoopsCaptchaImage extends XoopsCaptchaMethod |
||
| 29 | { |
||
| 30 | |||
| 31 | /** |
||
| 32 | * XoopsCaptchaImage::isActive() |
||
| 33 | * |
||
| 34 | * @return bool |
||
| 35 | */ |
||
| 36 | 1 | public function isActive() |
|
| 37 | { |
||
| 38 | 1 | if (!extension_loaded('gd')) { |
|
| 39 | trigger_error('GD library is not loaded', E_USER_WARNING); |
||
| 40 | return false; |
||
| 41 | View Code Duplication | } else { |
|
| 42 | $required_functions = array( |
||
| 43 | 1 | 'imagecreatetruecolor' , |
|
| 44 | 'imagecolorallocate' , |
||
| 45 | 'imagefilledrectangle' , |
||
| 46 | 'imagejpeg' , |
||
| 47 | 'imagedestroy' , |
||
| 48 | 'imageftbbox'); |
||
| 49 | 1 | foreach ($required_functions as $func) { |
|
| 50 | 1 | if (!function_exists($func)) { |
|
| 51 | trigger_error('Function ' . $func . ' is not defined', E_USER_WARNING); |
||
| 52 | return false; |
||
| 53 | } |
||
| 54 | } |
||
| 55 | } |
||
| 56 | 1 | return true; |
|
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * XoopsCaptchaImage::render() |
||
| 61 | * |
||
| 62 | * @return string |
||
| 63 | */ |
||
| 64 | 1 | public function render() |
|
| 83 | |||
| 84 | /** |
||
| 85 | * XoopsCaptchaImage::loadImage() |
||
| 86 | * |
||
| 87 | * @return string |
||
| 88 | */ |
||
| 89 | 2 | public function loadImage() |
|
| 94 | } |
||
| 95 |