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 |
||
11 | class ThreemaGateway_Option_DebugModeLog |
||
12 | { |
||
13 | /** |
||
14 | * @var string Default file path |
||
15 | */ |
||
16 | const DEFAULT_PATH = 'internal_data/threemagateway/receivedmsgs.log'; |
||
17 | |||
18 | /** |
||
19 | * Renders the debug mode log setting. |
||
20 | * |
||
21 | * Basically it just hides the setting if the debug mode of XenForo is disabled. |
||
22 | * |
||
23 | * @param XenForo_View $view View object |
||
24 | * @param string $fieldPrefix Prefix for the HTML form field name |
||
25 | * @param array $preparedOption Prepared option info |
||
26 | * @param bool $canEdit True if an "edit" link should appear |
||
27 | * |
||
28 | * @return XenForo_Template_Abstract Template object |
||
29 | */ |
||
30 | public static function renderOption(XenForo_View $view, $fieldPrefix, array $preparedOption, $canEdit) |
||
52 | |||
53 | /** |
||
54 | * Verifies whether the dir of the file is valid (can be created) and is writable. |
||
55 | * |
||
56 | * @param string $filepath Input |
||
57 | * @param XenForo_DataWriter $dataWriter |
||
58 | * @param string $fieldName Name of field/option |
||
59 | * |
||
60 | * @return bool |
||
61 | */ |
||
62 | public static function verifyOption(&$filepath, XenForo_DataWriter $dataWriter, $fieldName) |
||
79 | |||
80 | /** |
||
81 | * Remove the log file. |
||
82 | * |
||
83 | * @param array $option option setting |
||
84 | * @return bool |
||
85 | */ |
||
86 | public static function removeLog($option) |
||
99 | |||
100 | /** |
||
101 | * Corrects the option array. |
||
102 | * |
||
103 | * @param array $option |
||
104 | * @return string |
||
105 | */ |
||
106 | protected static function correctOption($option) |
||
130 | } |
||
131 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.