Completed
Pull Request — master (#27)
by Michael
01:42
created

Task   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 65
Duplicated Lines 18.46 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 12 12 1
A getForm() 0 40 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
 You may not change or alter any portion of this comment or credits
7
 of supporting developers from this source code or any supporting source code
8
 which is considered copyrighted (c) material of the original comment or credit authors.
9
10
 This program is distributed in the hope that it will be useful,
11
 but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
*/
14
15
/**
16
 * xnewsletter module for xoops
17
 *
18
 * @copyright       The TXMod XOOPS Project http://sourceforge.net/projects/thmod/
19
 * @copyright       XOOPS Project (https://xoops.org)
20
 * @license         GPL 2.0 or later
21
 * @package         xnewsletter
22
 * @since           2.5.x
23
 * @author          XOOPS Development Team ( [email protected] ) - ( https://xoops.org )
24
 */
25
26
//use XoopsModules\Xnewsletter;
27
28
// defined("XOOPS_ROOT_PATH") || die("XOOPS root path not defined");
29
require_once dirname(__DIR__) . '/include/common.php';
30
31
/**
32
 * Class Task
33
 */
34
class Task extends \XoopsObject
35
{
36
    public $helper = null;
37
38
    //Constructor
39
40 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...
41
    {
42
        $this->helper = Helper::getInstance();
43
        $this->db     = \XoopsDatabaseFactory::getDatabaseConnection();
44
        parent::__construct();
45
        $this->initVar('task_id', XOBJ_DTYPE_INT, null, false);
46
        $this->initVar('task_letter_id', XOBJ_DTYPE_INT, null, false);
47
        $this->initVar('task_subscr_id', XOBJ_DTYPE_INT, null, false);
48
        $this->initVar('task_starttime', XOBJ_DTYPE_INT, null, false);
49
        $this->initVar('task_submitter', XOBJ_DTYPE_INT, null, false);
50
        $this->initVar('task_created', XOBJ_DTYPE_INT, time(), false);
51
    }
52
53
    /**
54
     * @param bool $action
55
     *
56
     * @return \XoopsThemeForm
57
     */
58
    public function getForm($action = false)
59
    {
60
        global $xoopsDB;
61
62
        if (false === $action) {
63
            $action = $_SERVER['REQUEST_URI'];
64
        }
65
66
        $title = $this->isNew() ? sprintf(_AM_XNEWSLETTER_TASK_ADD) : sprintf(_AM_XNEWSLETTER_TASK_EDIT);
67
68
        require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
69
70
        $form = new \XoopsThemeForm($title, 'form', $action, 'post', true);
71
        $form->setExtra('enctype="multipart/form-data"');
72
73
        $letterCriteria = new \CriteriaCompo();
74
        $letterCriteria->setSort('letter_id');
75
        $letterCriteria->setOrder('DESC');
76
        $letter_select = new \XoopsFormSelect(_AM_XNEWSLETTER_TASK_LETTER_ID, 'task_letter_id', $this->getVar('task_letter_id'));
77
        $letter_select->addOptionArray($this->helper->getHandler('Letter')->getList($letterCriteria));
78
        $form->addElement($letter_select, true);
79
80
        $subscrCriteria = new \CriteriaCompo();
81
        $subscrCriteria->setSort('subscr_id');
82
        $subscrCriteria->setOrder('ASC');
83
        $subscr_select = new \XoopsFormSelect(_AM_XNEWSLETTER_TASK_SUBSCR_ID, 'task_subscr_id', $this->getVar('task_subscr_id'));
84
        $subscr_select->addOptionArray($this->helper->getHandler('Subscr')->getList($subscrCriteria));
85
        $form->addElement($subscr_select, true);
86
87
        $form->addElement(new \XoopsFormTextDateSelect(_AM_XNEWSLETTER_TASK_STARTTIME, 'task_starttime', '', $this->getVar('task_starttime')));
88
89
        $form->addElement(new \XoopsFormSelectUser(_AM_XNEWSLETTER_TASK_SUBMITTER, 'task_submitter', false, $this->getVar('task_submitter'), 1, false), true);
90
91
        $form->addElement(new \XoopsFormTextDateSelect(_AM_XNEWSLETTER_TASK_CREATED, 'task_created', '', $this->getVar('task_created')));
92
93
        $form->addElement(new \XoopsFormHidden('op', 'save_task'));
94
        $form->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
95
96
        return $form;
97
    }
98
}
99