Passed
Branch master (465698)
by Michael
05:38
created

PedigreeOwnerHandler   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 37
loc 37
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getActiveCriteria() 0 20 1
A __construct() 0 3 1

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
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
/**
12
 * Pedigree module for XOOPS
13
 *
14
 * @copyright       XOOPS Project (http://xoops.org)
15
 * @license         GPL 2.0 or later
16
 * @package         pedigree
17
 * @since           2.5.x
18
 * @author          XOOPS Module Dev Team (http://xoops.org)
19
 */
20
21
defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
22
23
/**
24
 * Class PedigreeOwner
25
 */
26
class PedigreeOwner extends XoopsObject
27
{
28
    //Constructor
29
    /**
30
     *
31
     */
32
    public function __construct()
33
    {
34
        parent::__construct();
35
        $this->initVar('Id', XOBJ_DTYPE_INT, null, false, 11);
36
        $this->initVar('firstname', XOBJ_DTYPE_TXTBOX, null, false, 30);
37
        $this->initVar('lastname', XOBJ_DTYPE_TXTBOX, null, false, 30);
38
        $this->initVar('postcode', XOBJ_DTYPE_TXTBOX, null, false, 7);
39
        $this->initVar('city', XOBJ_DTYPE_TXTBOX, null, false, 50);
40
        $this->initVar('streetname', XOBJ_DTYPE_TXTBOX, null, false, 40);
41
        $this->initVar('housenumber', XOBJ_DTYPE_TXTBOX, null, false, 6);
42
        $this->initVar('phonenumber', XOBJ_DTYPE_TXTBOX, null, false, 14);
43
        $this->initVar('emailadres', XOBJ_DTYPE_TXTBOX, null, false, 40);
44
        $this->initVar('website', XOBJ_DTYPE_TXTBOX, null, false, 60);
45
        $this->initVar('user', XOBJ_DTYPE_TXTBOX, null, false, 20);
46
    }
47
48
    /**
49
     * @param bool $action
50
     *
51
     * @return XoopsThemeForm
52
     */
53
    public function getForm($action = false)
54
    {
55
        global $xoopsModuleConfig;
56
57
        if ($action === false) {
58
            $action = $_SERVER['REQUEST_URI'];
59
        }
60
61
        $title = $this->isNew() ? sprintf(_AM_PEDIGREE_OWNER_ADD) : sprintf(_AM_PEDIGREE_OWNER_EDIT);
62
63
        include_once(XOOPS_ROOT_PATH . '/class/xoopsformloader.php');
64
65
        $form = new XoopsThemeForm($title, 'form', $action, 'post', true);
66
        $form->setExtra('enctype="multipart/form-data"');
67
68
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_OWNER_FIRSTNAME, 'firstname', 50, 255, $this->getVar('firstname')), false);
0 ignored issues
show
Bug introduced by
It seems like $this->getVar('firstname') can also be of type array; however, parameter $value of XoopsFormText::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

68
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_OWNER_FIRSTNAME, 'firstname', 50, 255, /** @scrutinizer ignore-type */ $this->getVar('firstname')), false);
Loading history...
69
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_OWNER_LASTNAME, 'lastname', 50, 255, $this->getVar('lastname')), false);
70
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_OWNER_POSTCODE, 'postcode', 50, 255, $this->getVar('postcode')), false);
71
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_OWNER_CITY, 'city', 50, 255, $this->getVar('city')), false);
72
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_OWNER_STREETNAME, 'streetname', 50, 255, $this->getVar('streetname')), false);
73
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_OWNER_HOUSENUMBER, 'housenumber', 50, 255, $this->getVar('housenumber')), false);
74
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_OWNER_PHONENUMBER, 'phonenumber', 50, 255, $this->getVar('phonenumber')), false);
75
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_OWNER_EMAILADRES, 'emailadres', 50, 255, $this->getVar('emailadres')), false);
76
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_OWNER_WEBSITE, 'website', 50, 255, $this->getVar('website')), false);
77
        $form->addElement(new XoopsFormText(_AM_PEDIGREE_OWNER_USER, 'user', 50, 255, $this->getVar('user')), false);
78
79
        $form->addElement(new XoopsFormHidden('op', 'save_owner'));
80
81
        //Submit buttons
82
        $button_tray   = new XoopsFormElementTray('', '');
83
        $submit_button = new XoopsFormButton('', 'submit', _SUBMIT, 'submit');
84
        $button_tray->addElement($submit_button);
85
86
        $cancel_button = new XoopsFormButton('', '', _CANCEL, 'cancel');
87
        $cancel_button->setExtra('onclick="history.go(-1)"');
88
        $button_tray->addElement($cancel_button);
89
90
        $form->addElement($button_tray);
91
92
        return $form;
93
    }
94
}
95
96
/**
97
 * Class PedigreeOwnerHandler
98
 */
99
class PedigreeOwnerHandler extends XoopsPersistableObjectHandler
100
{
101
    /**
102
     * @param null|object|XoopsDatabase $db
103
     */
104
    public function __construct(XoopsDatabase $db)
105
    {
106
        parent::__construct($db, 'pedigree_owner', 'PedigreeOwner', 'Id', 'firstname');
107
    }
108
109
    /**
110
     * Get criteria for active animals
111
     *
112
     * @return CriteriaElement
113
     */
114
    public function getActiveCriteria()
115
    {
116
        $gperm_handler = xoops_getHandler('groupperm');
0 ignored issues
show
Unused Code introduced by
The assignment to $gperm_handler is dead and can be removed.
Loading history...
117
118
        //        $criteria = new CriteriaCompo(new Criteria('offline', false));
119
        //        $criteria->add(new Criteria('published', 0, '>'));
120
        //        $criteria->add(new Criteria('published', time(), '<='));
121
        //        $expiredCriteria = new CriteriaCompo(new Criteria('expired', 0));
122
        //        $expiredCriteria->add(new Criteria('expired', time(), '>='), 'OR');
123
        //        $criteria->add($expiredCriteria);
124
        // add criteria for categories that the user has permissions for
125
        //        $groups                   = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getGroups() : array(0 => XOOPS_GROUP_ANONYMOUS);
126
        //mb        $allowedDownCategoriesIds = $gperm_handler->getItemIds('WFDownCatPerm', $groups, $this->wfdownloads->getModule()->mid());
127
        //mb        $criteria->add(new Criteria('cid', '(' . implode(',', $allowedDownCategoriesIds) . ')', 'IN'));
128
129
        $criteria = new CriteriaCompo();
130
        $criteria->setSort('lastname ASC');
131
        $criteria->setOrder('ASC');
132
133
        return $criteria;
134
    }
135
}
136