Category   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A __toString() 0 3 1
A displayForm() 0 3 1
A renderForm() 0 23 2
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
use XoopsFormButtonTray;
28
use XoopsFormHidden;
29
use XoopsFormText;
30
use XoopsObject;
31
use XoopsThemeForm;
32
33
/**
34
 * Category
35
 *
36
 * Class used to handle all of the CRUD actions for FAQ categories
37
 *
38
 * @author   ::    John Neill
39
 * @copyright:: Copyright (c) 2009
40
 */
41
final class Category extends XoopsObject
42
{
43
    private $category_id;
0 ignored issues
show
introduced by
The private property $category_id is not used, and could be removed.
Loading history...
44
    private $category_title;
0 ignored issues
show
introduced by
The private property $category_title is not used, and could be removed.
Loading history...
45
    private $category_order;
0 ignored issues
show
introduced by
The private property $category_order is not used, and could be removed.
Loading history...
46
47
    /**
48
     * Constructor
49
     */
50
    public function __construct()
51
    {
52
        parent::__construct();
53
        $this->initVar('category_id', \XOBJ_DTYPE_INT, null, false);
54
        $this->initVar('category_title', \XOBJ_DTYPE_TXTBOX, null, true, 255);
55
        $this->initVar('category_order', \XOBJ_DTYPE_INT, 0, false);
56
    }
57
58
    /**
59
     * Display the category title
60
     *
61
     * @return string display the category title (filtered for display)
62
     */
63
    public function __toString()
64
    {
65
        return (string)$this->getVar('category_title', 's');
66
    }
67
68
    /**
69
     * Display the category edit form
70
     */
71
    public function displayForm(): void
72
    {
73
        echo $this->renderForm();
74
    }
75
76
    /**
77
     * Render the category edit form
78
     *
79
     * @return string HTML entities used to edit the catagory object
80
     */
81
    public function renderForm(): string
82
    {
83
        require_once $GLOBALS['xoops']->path('class/xoopsformloader.php');
84
        $permHelper = new Permission();
85
        \xoops_load('constants', \basename(\dirname(__DIR__)));
86
87
        $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

87
        $caption = ($this->isNew()) ? \_AM_XOOPSFAQ_CREATE_NEW : \sprintf(\_AM_XOOPSFAQ_MODIFY_ITEM, /** @scrutinizer ignore-type */ $this->getVar('category_title'));
Loading history...
88
89
        $form = new XoopsThemeForm($caption, 'content', \xoops_getenv('SCRIPT_NAME'), 'post', true);
90
        $form->addElement(new XoopsFormHidden('op', 'save'));
91
        $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

91
        $form->addElement(new XoopsFormHidden('category_id', /** @scrutinizer ignore-type */ $this->getVar('category_id')));
Loading history...
92
        // title
93
        $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

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