Passed
Push — master ( 6209eb...36ba5e )
by Michael
51s queued 14s
created

YogurtCategoryHandler   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 8
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 2
c 1
b 0
f 0
dl 0
loc 8
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
1
<?php
2
/**
3
 * Extended User Profile
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
13
 * @license             GNU GPL 2 (http://www.gnu.org/licenses/gpl-2.0.html)
14
 * @package             profile
15
 * @since               2.3.0
16
 * @author              Jan Pedersen
17
 * @author              Taiwen Jiang <[email protected]>
18
 */
19
20
// defined('XOOPS_ROOT_PATH') || exit("XOOPS root path not defined");
21
22
/**
23
 * @package             kernel
24
 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
25
 */
26
class YogurtCategory extends XoopsObject
27
{
28
    /**
29
     *
30
     */
31
    public function __construct()
32
    {
33
        $this->initVar('cat_id', XOBJ_DTYPE_INT, null, true);
34
        $this->initVar('cat_title', XOBJ_DTYPE_TXTBOX);
35
        $this->initVar('cat_description', XOBJ_DTYPE_TXTAREA);
36
        $this->initVar('cat_weight', XOBJ_DTYPE_INT);
37
    }
38
39
    /**
40
     * Get {@link XoopsThemeForm} for adding/editing categories
41
     *
42
     * @param mixed $action URL to submit to or false for $_SERVER['REQUEST_URI']
43
     *
44
     * @return object
45
     */
46
    public function getForm($action = false)
47
    {
48
        if ($action === false) {
49
            $action = $_SERVER['REQUEST_URI'];
50
        }
51
        $title = $this->isNew() ? sprintf(_AM_YOGURT_ADD, _AM_YOGURT_CATEGORY) : sprintf(_AM_YOGURT_EDIT, _AM_YOGURT_CATEGORY);
52
53
        include_once $GLOBALS['xoops']->path('class/xoopsformloader.php');
54
55
        $form = new XoopsThemeForm($title, 'form', $action, 'post', true);
56
        $form->addElement(new XoopsFormText(_AM_YOGURT_TITLE, 'cat_title', 35, 255, $this->getVar('cat_title')));
0 ignored issues
show
Bug introduced by
It seems like $this->getVar('cat_title') can also be of type array and 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

56
        $form->addElement(new XoopsFormText(_AM_YOGURT_TITLE, 'cat_title', 35, 255, /** @scrutinizer ignore-type */ $this->getVar('cat_title')));
Loading history...
57
        if (!$this->isNew()) {
58
            //Load groups
59
            $form->addElement(new XoopsFormHidden('id', $this->getVar('cat_id')));
0 ignored issues
show
Bug introduced by
It seems like $this->getVar('cat_id') can also be of type array and array; however, parameter $value of XoopsFormHidden::__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

59
            $form->addElement(new XoopsFormHidden('id', /** @scrutinizer ignore-type */ $this->getVar('cat_id')));
Loading history...
60
        }
61
        $form->addElement(new XoopsFormTextArea(_AM_YOGURT_DESCRIPTION, 'cat_description', $this->getVar('cat_description', 'e')));
0 ignored issues
show
Bug introduced by
It seems like $this->getVar('cat_description', 'e') can also be of type array and array; however, parameter $value of XoopsFormTextArea::__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

61
        $form->addElement(new XoopsFormTextArea(_AM_YOGURT_DESCRIPTION, 'cat_description', /** @scrutinizer ignore-type */ $this->getVar('cat_description', 'e')));
Loading history...
62
        $form->addElement(new XoopsFormText(_AM_YOGURT_WEIGHT, 'cat_weight', 35, 35, $this->getVar('cat_weight', 'e')));
63
64
        $form->addElement(new XoopsFormHidden('op', 'save'));
65
        $form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
66
67
        return $form;
68
    }
69
}
70
71
/**
72
 * @package             kernel
73
 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
74
 */
75
class YogurtCategoryHandler extends XoopsPersistableObjectHandler
76
{
77
    /**
78
     * @param null|XoopsDatabase $db
79
     */
80
    public function __construct(XoopsDatabase $db)
81
    {
82
        parent::__construct($db, 'yogurt_profile_category', 'Yogurtcategory', 'cat_id', 'cat_title');
83
    }
84
}
85