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 XoopsFormDhtmlTextArea extends XoopsFormTextArea |
||
| 33 | { |
||
| 34 | /** |
||
| 35 | * Extended HTML editor |
||
| 36 | * |
||
| 37 | * <p>If an extended HTML editor is set, the renderer will be replaced by the specified editor, usually a visual or WYSIWYG editor.</p> |
||
| 38 | * |
||
| 39 | * <ul>Developer and user guide: |
||
| 40 | * <li><ul>For run-time settings per call |
||
| 41 | * <li>To use an editor pre-configured by {@link XoopsEditor}, e.g. 'fckeditor': <code>$options['editor'] = 'fckeditor';</code></li> |
||
| 42 | * <li>To use a custom editor, e.g. 'MyEditor' class located in "/modules/myeditor/myeditor.php": <code>$options['editor'] = array('MyEditor', XOOPS_ROOT_PATH . "/modules/myeditor/myeditor.php");</code></li> |
||
| 43 | * </ul></li> |
||
| 44 | * <li><ul>For pre-configured settings, which will force to use a editor if no specific editor is set for call |
||
| 45 | * <li><ul>Set up custom configs: in XOOPS_VAR_PATH . '/configs/xoopsconfig.php' set a editor as default, e.g. |
||
| 46 | * <li>a pre-configured editor 'fckeditor': <code>return array('editor' => 'fckeditor');</code></li> |
||
| 47 | * <li>a custom editor 'MyEditor' class located in "/modules/myeditor/myeditor.php": <code>return array('editor' => array('MyEditor', XOOPS_ROOT_PATH . "/modules/myeditor/myeditor.php");</code></li> |
||
| 48 | * </ul></li> |
||
| 49 | * <li>To disable the default editor, in XOOPS_VAR_PATH . '/configs/xoopsconfig.php': <code>return array();</code></li> |
||
| 50 | * <li>To disable the default editor for a specific call: <code>$options['editor'] = 'dhtmltextarea';</code></li> |
||
| 51 | * </ul></li> |
||
| 52 | * </ul> |
||
| 53 | */ |
||
| 54 | public $htmlEditor = array(); |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Hidden text |
||
| 58 | * |
||
| 59 | * @var string |
||
| 60 | * @access private |
||
| 61 | */ |
||
| 62 | public $_hiddenText; |
||
| 63 | |||
| 64 | public $skipPreview = false; |
||
| 65 | public $doHtml = false; |
||
| 66 | public $js = ''; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Constructor |
||
| 70 | * |
||
| 71 | * @param string $caption Caption |
||
| 72 | * @param string $name "name" attribute |
||
| 73 | * @param string $value Initial text |
||
| 74 | * @param int $rows Number of rows |
||
| 75 | * @param int $cols Number of columns |
||
| 76 | * @param string $hiddentext Identifier for hidden Text |
||
| 77 | * @param array $options Extra options |
||
| 78 | */ |
||
| 79 | public function __construct($caption, $name, $value = '', $rows = 5, $cols = 50, $hiddentext = 'xoopsHiddenText', $options = array()) |
||
| 130 | |||
| 131 | /** |
||
| 132 | * Prepare HTML for output |
||
| 133 | * |
||
| 134 | * @return string HTML |
||
| 135 | */ |
||
| 136 | public function render() |
||
| 146 | |||
| 147 | /** |
||
| 148 | * XoopsFormDhtmlTextArea::renderValidationJS() |
||
| 149 | * |
||
| 150 | * @return bool|string |
||
| 151 | */ |
||
| 152 | public function renderValidationJS() |
||
| 162 | } |
||
| 163 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.