Passed
Pull Request — master (#81)
by Michael
02:55
created

Category   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 18
dl 0
loc 50
rs 10
c 1
b 0
f 0

2 Methods

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

64
        $form->addElement(new \XoopsFormText(_AM_YOGURT_TITLE, 'cat_title', 35, 255, /** @scrutinizer ignore-type */ $this->getVar('cat_title')));
Loading history...
65
66
        if (!$this->isNew()) {
67
            //Load groups
68
69
            $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

69
            $form->addElement(new \XoopsFormHidden('id', /** @scrutinizer ignore-type */ $this->getVar('cat_id')));
Loading history...
70
        }
71
72
        $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

72
        $form->addElement(new \XoopsFormTextArea(_AM_YOGURT_DESCRIPTION, 'cat_description', /** @scrutinizer ignore-type */ $this->getVar('cat_description', 'e')));
Loading history...
73
74
        $form->addElement(new \XoopsFormText(_AM_YOGURT_WEIGHT, 'cat_weight', 35, 35, $this->getVar('cat_weight', 'e')));
75
76
        $form->addElement(new \XoopsFormHidden('op', 'save'));
77
78
        $form->addElement(new \XoopsFormButton('', 'submit', \_SUBMIT, 'submit'));
79
80
        return $form;
81
    }
82
}
83