form_hotel_promotion   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 95
Duplicated Lines 45.26 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 43
loc 95
rs 10
c 0
b 0
f 0
wmc 8
lcom 0
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 10 10 1
A createElements() 0 28 5
A createButtons() 33 33 2

How to fix   Duplicated Code   

Duplicated Code

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
2
/**
3
 * @城市表单
4
 * @license   http://www.blags.org/
5
 * @created   :2010年05月20日 23时52分
6
 * @copyright 1997-2010 The Martin Group
7
 * @author    Martin <[email protected]>
8
 * */
9
if (!defined('XOOPS_ROOT_PATH')) {
10
    return;
11
}
12
13
include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
14
15
/**
16
 * Class form_hotel_promotion
17
 */
18
class form_hotel_promotion extends XoopsThemeForm
19
{
20
    /**
21
     * form_hotel_promotion constructor.
22
     * @param $HotelPromotionObj
23
     * @param $HotelList
24
     */
25 View Code Duplication
    public function __construct(&$HotelPromotionObj, &$HotelList)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
26
    {
27
        $this->Obj       = &$HotelPromotionObj;
28
        $this->HotelList = &$HotelList;
29
        parent::__construct(_AM_MARTIN_HOTEL_CITY_LIST, "op", xoops_getenv('PHP_SELF') . "?action=save");
30
        $this->setExtra('enctype="multipart/form-data"');
31
32
        $this->createElements();
33
        $this->createButtons();
34
    }
35
36
    /**
37
     * created elements
38
     * @license   http://www.blags.org/
39
     * @created   :2010年05月21日 20时40分
40
     * @copyright 1997-2010 The Martin Group
41
     * @author    Martin <[email protected]>
42
     * */
43
    public function createElements()
44
    {
45
        //include_once MARTIN_ROOT_PATH . '/include/formdatetime.php';
46
        include_once XOOPS_ROOT_PATH . "/modules/martin/class/xoopsformloader.php";
47
48
        $js          = '<script type=\'text/javascript\'>
49
            jQuery.noConflict();
50
            </script>';
51
        $RoomElement = new XoopsFormSelect($js . _AM_MARTIN_PROMO_HOTELS, 'hotel_id', $this->HotelList, 0, false);
52
        $RoomElement->addOptionArray($this->HotelList);
53
        $this->addElement($RoomElement, false);
54
55
        $this->addElement(new XoopsFormTextDateSelect(_AM_MARTIN_PROMO_START, 'promotion_start_date', $size = 15, $this->Obj->promotion_start_date(), false), true);
56
57
        $this->addElement(new XoopsFormTextDateSelect(_AM_MARTIN_PROMO_END, 'promotion_end_date', $size = 15, $this->Obj->promotion_end_date(), false), true);
58
59
        $editor                   = 'tinymce';
60
        $editor_configs           = array();
61
        $editor_configs["name"]   = "promotion_description";
62
        $editor_configs["value"]  = $this->Obj->promotion_description();
63
        $editor_configs["rows"]   = empty($xoopsModuleConfig["editor_rows"]) ? 35 : $xoopsModuleConfig["editor_rows"];
0 ignored issues
show
Bug introduced by
The variable $xoopsModuleConfig seems to never exist, and therefore empty should always return true. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
64
        $editor_configs["cols"]   = empty($xoopsModuleConfig["editor_cols"]) ? 60 : $xoopsModuleConfig["editor_cols"];
65
        $editor_configs["width"]  = empty($xoopsModuleConfig["editor_width"]) ? "100%" : $xoopsModuleConfig["editor_width"];
66
        $editor_configs["height"] = empty($xoopsModuleConfig["editor_height"]) ? "400px" : $xoopsModuleConfig["editor_height"];
67
        $this->addElement(new XoopsFormEditor(_AM_MARTIN_PROMOTION_DETAILS, $editor, $editor_configs, false, $onfailure = null), false);
68
69
        $this->addElement(new XoopsFormHidden('id', $this->Obj->promotion_id()));
70
    }
71
72
    /**
73
     * @创建按钮
74
     * @license   http://www.blags.org/
75
     * @created   :2010年05月20日 23时52分
76
     * @copyright 1997-2010 The Martin Group
77
     * @author    Martin <[email protected]>
78
     * */
79 View Code Duplication
    public function createButtons()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
80
    {
81
        $button_tray = new XoopsFormElementTray('', '');
82
        // No ID for category -- then it's new category, button says 'Create'
83
        if (!$this->Obj->promotion_id()) {
84
            $butt_create = new XoopsFormButton('', '', _SUBMIT, 'submit');
85
            $butt_create->setExtra('onclick="this.form.elements.op.value=\'addcategory\'"');
86
            $button_tray->addElement($butt_create);
87
88
            $butt_clear = new XoopsFormButton('', '', _RESET, 'reset');
89
            $button_tray->addElement($butt_clear);
90
91
            $butt_cancel = new XoopsFormButton('', '', _CANCEL, 'button');
92
            $butt_cancel->setExtra('onclick="history.go(-1)"');
93
            $button_tray->addElement($butt_cancel);
94
95
            $this->addElement($button_tray);
96
        } else {
97
            // button says 'Update'
98
            $butt_create = new XoopsFormButton('', '', _EDIT, 'submit');
99
            $butt_create->setExtra('onclick="this.form.elements.op.value=\'addcategory\'"');
100
            $button_tray->addElement($butt_create);
101
102
            $butt_clear = new XoopsFormButton('', '', _RESET, 'reset');
103
            $button_tray->addElement($butt_clear);
104
105
            $butt_cancel = new XoopsFormButton('', '', _CANCEL, 'button');
106
            $butt_cancel->setExtra('onclick="history.go(-1)"');
107
            $button_tray->addElement($butt_cancel);
108
109
            $this->addElement($button_tray);
110
        }
111
    }
112
}
113