Completed
Push — master ( 592643...f454c2 )
by Michael
03:05 queued 01:21
created

Protocol   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 76
Duplicated Lines 18.42 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 14
loc 76
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 14 14 1
A getForm() 0 41 3

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
namespace XoopsModules\Xnewsletter;
4
5
/**
6
 * ****************************************************************************
7
 *  - A Project by Developers TEAM For Xoops - ( https://xoops.org )
8
 * ****************************************************************************
9
 *  XNEWSLETTER - MODULE FOR XOOPS
10
 *  Copyright (c) 2007 - 2012
11
 *  Goffy ( wedega.com )
12
 *
13
 *  You may not change or alter any portion of this comment or credits
14
 *  of supporting developers from this source code or any supporting
15
 *  source code which is considered copyrighted (c) material of the
16
 *  original comment or credit authors.
17
 *
18
 *  This program is distributed in the hope that it will be useful,
19
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 *  GNU General Public License for more details.
22
 *  ---------------------------------------------------------------------------
23
 * @copyright  Goffy ( wedega.com )
24
 * @license    GPL 2.0
25
 * @package    xnewsletter
26
 * @author     Goffy ( [email protected] )
27
 *
28
 * ****************************************************************************
29
 */
30
31
//use XoopsModules\Xnewsletter;
32
33
require_once dirname(__DIR__) . '/include/common.php';
34
35
/**
36
 * Class Protocol
37
 */
38
class Protocol extends \XoopsObject
39
{
40
    public $helper = null;
41
42
    public $protocol_status_strs = [
43
        _XNEWSLETTER_PROTOCOL_STATUS_SAVED             => _AM_XNEWSLETTER_PROTOCOL_STATUS_SAVED,
44
        _XNEWSLETTER_PROTOCOL_STATUS_ERROR_CREATE_TASK => _AM_XNEWSLETTER_PROTOCOL_STATUS_ERROR_CREATE_TASK,
45
        _XNEWSLETTER_PROTOCOL_STATUS_OK_SEND_TEST      => _AM_XNEWSLETTER_PROTOCOL_STATUS_OK_SEND_TEST,
46
        _XNEWSLETTER_PROTOCOL_STATUS_OK_SEND           => _AM_XNEWSLETTER_PROTOCOL_STATUS_OK_SEND,
47
        _XNEWSLETTER_PROTOCOL_STATUS_ERROR_SEND        => _AM_XNEWSLETTER_PROTOCOL_STATUS_ERROR_SEND,// INPROGRESS
48
    ];
49
50
    //Constructor
51
52 View Code Duplication
    public function __construct()
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...
53
    {
54
        $this->helper = Helper::getInstance();
55
        $this->db     = \XoopsDatabaseFactory::getDatabaseConnection();
56
        $this->initVar('protocol_id', XOBJ_DTYPE_INT, null, false);
57
        $this->initVar('protocol_letter_id', XOBJ_DTYPE_INT, null, false);
58
        $this->initVar('protocol_subscriber_id', XOBJ_DTYPE_INT, null, false);
59
        $this->initVar('protocol_status', XOBJ_DTYPE_TXTBOX, '', false, 200); // old style
60
        $this->initVar('protocol_success', XOBJ_DTYPE_OTHER, null, false); // boolean
61
        $this->initVar('protocol_submitter', XOBJ_DTYPE_INT, null, false);
62
        $this->initVar('protocol_created', XOBJ_DTYPE_INT, null, false);
63
        $this->initVar('protocol_status_str_id', XOBJ_DTYPE_TXTBOX, '', false); // new from v1.3
64
        $this->initVar('protocol_status_vars', XOBJ_DTYPE_ARRAY, [], false); // new from v1.3
65
    }
66
67
    /**
68
     * @param bool $action
69
     *
70
     * @return \XoopsThemeForm
71
     */
72
    public function getForm($action = false)
73
    {
74
        global $xoopsDB;
75
76
        if (false === $action) {
77
            $action = $_SERVER['REQUEST_URI'];
78
        }
79
80
        $title = $this->isNew() ? sprintf(_AM_XNEWSLETTER_PROTOCOL_ADD) : sprintf(_AM_XNEWSLETTER_PROTOCOL_EDIT);
81
82
        require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
83
        $form = new \XoopsThemeForm($title, 'form', $action, 'post', true);
84
        $form->setExtra('enctype="multipart/form-data"');
85
86
        $letterCriteria = new \CriteriaCompo();
87
        $letterCriteria->setSort('letter_id');
88
        $letterCriteria->setOrder('DESC');
89
        $letter_select = new \XoopsFormSelect(_AM_XNEWSLETTER_PROTOCOL_LETTER_ID, 'protocol_letter_id', $this->getVar('protocol_letter_id'));
90
        $letter_select->addOptionArray($this->helper->getHandler('Letter')->getList($letterCriteria));
91
        $form->addElement($letter_select, true);
92
93
        $subscrCriteria = new \CriteriaCompo();
94
        $subscrCriteria->setSort('subscr_id');
95
        $subscrCriteria->setOrder('ASC');
96
        $subscr_select = new \XoopsFormSelect(_AM_XNEWSLETTER_PROTOCOL_SUBSCRIBER_ID, 'protocol_subscriber_id', $this->getVar('protocol_subscriber_id'));
97
        $subscr_select->addOptionArray($this->helper->getHandler('Subscr')->getList($subscrCriteria));
98
        $form->addElement($subscr_select, true);
99
100
        $form->addElement(new \XoopsFormText(_AM_XNEWSLETTER_PROTOCOL_STATUS, 'protocol_status', 50, 200, $this->getVar('protocol_status')), false);
101
102
        $form->addElement(new \XoopsFormText(_AM_XNEWSLETTER_PROTOCOL_SUCCESS, 'protocol_success', 50, 255, $this->getVar('protocol_success')), false);
103
104
        $form->addElement(new \XoopsFormSelectUser(_AM_XNEWSLETTER_PROTOCOL_SUBMITTER, 'protocol_submitter', false, $this->getVar('protocol_submitter'), 1, false), true);
105
106
        $form->addElement(new \XoopsFormTextDateSelect(_AM_XNEWSLETTER_PROTOCOL_CREATED, 'protocol_created', '', $this->getVar('protocol_created')));
107
108
        $form->addElement(new \XoopsFormHidden('op', 'save_protocol'));
109
        $form->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
110
111
        return $form;
112
    }
113
}
114