Category   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A displayForm() 0 3 1
A renderForm() 0 23 2
A __toString() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Xoopsfaq;
4
5
/*
6
 You may not change or alter any portion of this comment or credits of
7
 supporting developers from this source code or any supporting source code
8
 which is considered copyrighted (c) material of the original comment or credit
9
 authors.
10
11
 This program is distributed in the hope that it will be useful, but
12
 WITHOUT ANY WARRANTY; without even the implied warranty of
13
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 */
15
16
/**
17
 * XOOPS FAQ Category & Category Handler Class Definitions
18
 *
19
 * @author    John Neill
20
 * @author    XOOPS Module Development Team
21
 * @copyright Copyright (c) 2001-2017 {@link https://xoops.org XOOPS Project}
22
 * @license   https://www.gnu.org/licenses/gpl-2.0.html GNU Public License
23
 * @since     ::   1.23
24
 */
25
26
use Xmf\Module\Helper\Permission;
27
28
/**
29
 * Category
30
 *
31
 * Class used to handle all of the CRUD actions for FAQ categories
32
 *
33
 * @author   ::    John Neill
34
 * @copyright:: Copyright (c) 2009
35
 */
36
class Category extends \XoopsObject
37
{
38
    /**
39
     * @readonly
40
     */
41
    private int $category_id;
0 ignored issues
show
introduced by
The private property $category_id is not used, and could be removed.
Loading history...
42
    /**
43
     * @readonly
44
     */
45
    private string $category_title;
0 ignored issues
show
introduced by
The private property $category_title is not used, and could be removed.
Loading history...
46
    /**
47
     * @readonly
48
     */
49
    private int $category_order;
0 ignored issues
show
introduced by
The private property $category_order is not used, and could be removed.
Loading history...
50
51
    /**
52
     * Constructor
53
     */
54
    public function __construct()
55
    {
56
        parent::__construct();
57
        $this->initVar('category_id', \XOBJ_DTYPE_INT, null, false);
58
        $this->initVar('category_title', \XOBJ_DTYPE_TXTBOX, null, true, 255);
59
        $this->initVar('category_order', \XOBJ_DTYPE_INT, 0, false);
60
    }
61
62
    /**
63
     * Display the category title
64
     *
65
     * @return string display the category title (filtered for display)
66
     */
67
    public function __toString(): string
68
    {
69
        return (string)$this->getVar('category_title', 's');
70
    }
71
72
    /**
73
     * Display the category edit form
74
     */
75
    public function displayForm(): void
76
    {
77
        echo $this->renderForm();
78
    }
79
80
    /**
81
     * Render the category edit form
82
     *
83
     * @return string HTML entities used to edit the catagory object
84
     */
85
    public function renderForm(): string
86
    {
87
        require_once \dirname(__DIR__, 3) . '/class/xoopsformloader.php';
88
        $permHelper = new Permission();
89
        \xoops_load('constants', \basename(\dirname(__DIR__)));
90
91
        $caption = ($this->isNew()) ? \_AM_XOOPSFAQ_CREATE_NEW : \sprintf(\_AM_XOOPSFAQ_MODIFY_ITEM, $this->getVar('category_title'));
0 ignored issues
show
Bug introduced by
It seems like $this->getVar('category_title') can also be of type array and array; however, parameter $values of sprintf() does only seem to accept double|integer|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

91
        $caption = ($this->isNew()) ? \_AM_XOOPSFAQ_CREATE_NEW : \sprintf(\_AM_XOOPSFAQ_MODIFY_ITEM, /** @scrutinizer ignore-type */ $this->getVar('category_title'));
Loading history...
92
93
        $form = new \XoopsThemeForm($caption, 'content', \xoops_getenv('SCRIPT_NAME'), 'post', true);
94
        $form->addElement(new \XoopsFormHidden('op', 'save'));
95
        $form->addElement(new \XoopsFormHidden('category_id', $this->getVar('category_id')));
0 ignored issues
show
Bug introduced by
It seems like $this->getVar('category_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

95
        $form->addElement(new \XoopsFormHidden('category_id', /** @scrutinizer ignore-type */ $this->getVar('category_id')));
Loading history...
96
        // title
97
        $category_title = new \XoopsFormText(\_AM_XOOPSFAQ_E_CATEGORY_TITLE, 'category_title', 50, 150, $this->getVar('category_title', 'e'));
0 ignored issues
show
Bug introduced by
It seems like $this->getVar('category_title', 'e') 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

97
        $category_title = new \XoopsFormText(\_AM_XOOPSFAQ_E_CATEGORY_TITLE, 'category_title', 50, 150, /** @scrutinizer ignore-type */ $this->getVar('category_title', 'e'));
Loading history...
98
        $category_title->setDescription(\_AM_XOOPSFAQ_E_CATEGORY_TITLE_DESC);
99
        $form->addElement($category_title, true);
100
        // order
101
        $category_order = new \XoopsFormText(\_AM_XOOPSFAQ_E_CATEGORY_ORDER, 'category_order', 5, 5, $this->getVar('category_order', 'e'));
102
        $category_order->setDescription(\_AM_XOOPSFAQ_E_CATEGORY_ORDER_DESC);
103
        $form->addElement($category_order, false);
104
        $form->addElement($permHelper->getGroupSelectFormForItem('viewcat', $this->getVar('category_id'), \_AM_XOOPSFAQ_CATEGORY_GROUP_PERMS, '', (bool)Constants::INCLUDE_ANNON));
105
        $form->addElement(new \XoopsFormButtonTray('category_form', \_SUBMIT, 'submit'));
106
107
        return $form->render();
108
    }
109
}
110