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 |
||
15 | class calendar_wizard_import_ical |
||
16 | { |
||
17 | /** |
||
18 | * List of steps. Key is the function, value is the translated title. |
||
19 | */ |
||
20 | public $steps; |
||
21 | |||
22 | /** |
||
23 | * List of eTemplates to use for each step. You can override this with your own etemplates steps. |
||
24 | */ |
||
25 | protected $step_templates = array( |
||
26 | 'wizard_step55' => 'calendar.import.conditions' |
||
27 | ); |
||
28 | /** |
||
29 | * constructor |
||
30 | */ |
||
31 | function __construct() |
||
37 | |||
38 | function wizard_step50(&$content, &$sel_options, &$readonlys, &$preserv) |
||
45 | |||
46 | // Conditions |
||
47 | function wizard_step55(&$content, &$sel_options, &$readonlys, &$preserv) |
||
84 | } |
||
85 |
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return
,die
orexit
statements that have been added for debug purposes.In the above example, the last
return false
will never be executed, because a return statement has already been met in every possible execution path.