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 |
||
12 | class cm_cs_redirect_old_order { |
||
13 | var $code; |
||
14 | var $group; |
||
15 | var $title; |
||
16 | var $description; |
||
17 | var $sort_order; |
||
18 | var $enabled = false; |
||
19 | |||
20 | function __construct() { |
||
32 | |||
33 | function execute() { |
||
34 | global $order_id; |
||
35 | |||
36 | $OSCOM_Db = Registry::get('Db'); |
||
37 | |||
38 | View Code Duplication | if ( (int)MODULE_CONTENT_CHECKOUT_SUCCESS_REDIRECT_OLD_ORDER_MINUTES > 0 ) { |
|
|
|||
39 | $Qcheck = $OSCOM_Db->prepare('select 1 from :table_orders where orders_id = :orders_id and date_purchased < date_sub(now(), interval :limit_minutes minute) limit 1'); |
||
40 | $Qcheck->bindInt(':orders_id', $order_id); |
||
41 | $Qcheck->bindInt(':limit_minutes', MODULE_CONTENT_CHECKOUT_SUCCESS_REDIRECT_OLD_ORDER_MINUTES); |
||
42 | $Qcheck->execute(); |
||
43 | |||
44 | if ($Qcheck->fetch() !== false) { |
||
45 | OSCOM::redirect('account.php'); |
||
46 | } |
||
47 | } |
||
48 | } |
||
49 | |||
50 | function isEnabled() { |
||
53 | |||
54 | function check() { |
||
57 | |||
58 | function install() { |
||
92 | |||
93 | function remove() { |
||
96 | |||
97 | function keys() { |
||
100 | } |
||
101 | ?> |
||
102 |
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.