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 |
||
26 | class XoopsCaptchaText extends XoopsCaptchaMethod |
||
27 | { |
||
28 | /** |
||
29 | * XoopsCaptchaText::render() |
||
30 | * |
||
31 | * @return string |
||
32 | */ |
||
33 | 1 | public function render() |
|
34 | { |
||
35 | 1 | $form = $this->loadText() . ' <input type="text" name="' . $this->config['name'] |
|
36 | 1 | . '" id="' . $this->config['name'] . '" size="' . $this->config['num_chars'] |
|
37 | 1 | . '" maxlength="' . $this->config['num_chars'] . '" value="" />'; |
|
38 | 1 | $form .= '<br />' . XoopsLocale::INPUT_RESULT_FROM_EXPRESSION; |
|
39 | 1 | View Code Duplication | if (!empty($this->config['maxattempts'])) { |
40 | $form .= '<br />' . sprintf(XoopsLocale::F_MAXIMUM_ATTEMPTS, $this->config['maxattempts']); |
||
41 | } |
||
42 | 1 | return $form; |
|
43 | } |
||
44 | |||
45 | /** |
||
46 | * XoopsCaptchaText::loadText() |
||
47 | * |
||
48 | * @return string |
||
49 | */ |
||
50 | 2 | public function loadText() |
|
63 | } |
||
64 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.