Category::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Suico;
4
5
/**
6
 * Extended User Profile
7
 *
8
 * You may not change or alter any portion of this comment or credits
9
 * of supporting developers from this source code or any supporting source code
10
 * which is considered copyrighted (c) material of the original comment or credit authors.
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 *
15
 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
16
 * @license             GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html)
17
 * @since               2.3.0
18
 * @author              Jan Pedersen
19
 * @author              Taiwen Jiang <[email protected]>
20
 */
21
22
/**
23
 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
24
 */
25
class Category extends \XoopsObject
26
{
27
    public $cat_id;
28
    public $cat_title;
29
    public $cat_description;
30
    public $cat_weight;
31
32
    public function __construct()
33
    {
34
        $this->initVar('cat_id', \XOBJ_DTYPE_INT, null, true);
35
        $this->initVar('cat_title', \XOBJ_DTYPE_TXTBOX);
36
        $this->initVar('cat_description', \XOBJ_DTYPE_TXTAREA);
37
        $this->initVar('cat_weight', \XOBJ_DTYPE_INT);
38
    }
39
40
    /**
41
     * Get {@link XoopsThemeForm} for adding/editing categories
42
     *
43
     * @param mixed $action URL to submit to or false for $_SERVER['REQUEST_URI']
44
     *
45
     * @return object
46
     */
47
    public function getForm($action = false)
48
    {
49
        if (false === $action) {
50
            $action = $_SERVER['REQUEST_URI'];
51
        }
52
        $title = $this->isNew() ? \sprintf(\_AM_SUICO_ADD, \_AM_SUICO_CATEGORY) : \sprintf(\_AM_SUICO_EDIT, \_AM_SUICO_CATEGORY);
53
        require_once $GLOBALS['xoops']->path('class/xoopsformloader.php');
54
        $form = new \XoopsThemeForm($title, 'form', $action, 'post', true);
55
        $form->addElement(new \XoopsFormText(\_AM_SUICO_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

55
        $form->addElement(new \XoopsFormText(\_AM_SUICO_TITLE, 'cat_title', 35, 255, /** @scrutinizer ignore-type */ $this->getVar('cat_title')));
Loading history...
56
        if (!$this->isNew()) {
57
            //Load groups
58
            $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

58
            $form->addElement(new \XoopsFormHidden('id', /** @scrutinizer ignore-type */ $this->getVar('cat_id')));
Loading history...
59
        }
60
        $form->addElement(new \XoopsFormTextArea(\_AM_SUICO_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

60
        $form->addElement(new \XoopsFormTextArea(\_AM_SUICO_DESCRIPTION, 'cat_description', /** @scrutinizer ignore-type */ $this->getVar('cat_description', 'e')));
Loading history...
61
        $form->addElement(new \XoopsFormText(\_AM_SUICO_WEIGHT, 'cat_weight', 35, 35, $this->getVar('cat_weight', 'e')));
62
        $form->addElement(new \XoopsFormHidden('op', 'save'));
63
        $form->addElement(new \XoopsFormButton('', 'submit', \_SUBMIT, 'submit'));
64
65
        return $form;
66
    }
67
}
68