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 namespace XoopsModules\Extcal; |
||
14 | class TableForm extends \XoopsForm |
||
15 | { |
||
16 | /** |
||
17 | * ad the balise html "table" to render. |
||
18 | * |
||
19 | * @var bool|string |
||
20 | */ |
||
21 | public $_addBaliseTable = ''; |
||
22 | |||
23 | /** |
||
24 | * Gets the "value" attribute of a form element. |
||
25 | * |
||
26 | * @param $addBaliseTable |
||
27 | * |
||
28 | * @internal param string $name the "name" attribute of a form element |
||
29 | * @internal param bool $encode To sanitizer the text? |
||
30 | * |
||
31 | * @return string the "value" attribute assigned to a form element, null if not set |
||
32 | */ |
||
33 | public function setAddBaliseTable($addBaliseTable) |
||
37 | |||
38 | /** |
||
39 | * gets the "value" attribute of all form elements. |
||
40 | * |
||
41 | * @internal param bool $encode To sanitizer the text? |
||
42 | * |
||
43 | * @return array array of name/value pairs assigned to form elements |
||
44 | */ |
||
45 | public function getAddBaliseTable() |
||
49 | |||
50 | /** |
||
51 | * Insert an empty row in the table to serve as a seperator. |
||
52 | * |
||
53 | * @param string $extra HTML to be displayed in the empty row. |
||
54 | * @param string $class CSS class name for <td> tag |
||
55 | */ |
||
56 | public function insertBreak($extra = '', $class = '') |
||
68 | |||
69 | /** |
||
70 | * create HTML to output the form as a theme-enabled table with validation. |
||
71 | * |
||
72 | * YOU SHOULD AVOID TO USE THE FOLLOWING Nocolspan METHOD, IT WILL BE REMOVED |
||
73 | * |
||
74 | * To use the noColspan simply use the following example: |
||
75 | * |
||
76 | * $colspan = new \XoopsFormDhtmlTextArea( '', 'key', $value, '100%', '100%' ); |
||
77 | * $colspan->setNocolspan(); |
||
78 | * $form->addElement( $colspan ); |
||
79 | * |
||
80 | * @return string |
||
81 | */ |
||
82 | public function render() |
||
137 | } // fin de la classe |
||
138 |
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.