Review   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 66
dl 0
loc 103
rs 10
c 0
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getForm() 0 67 4
A __construct() 0 18 3
1
<?php
2
3
namespace XoopsModules\Wfdownloads;
4
5
/*
6
 You may not change or alter any portion of this comment or credits
7
 of supporting developers from this source code or any supporting source code
8
 which is considered copyrighted (c) material of the original comment or credit authors.
9
10
 This program is distributed in the hope that it will be useful,
11
 but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 */
14
15
/**
16
 * Wfdownloads module
17
 *
18
 * @copyright       XOOPS Project (https://xoops.org)
19
 * @license         GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
20
 * @package         wfdownload
21
 * @since           3.23
22
 * @author          Xoops Development Team
23
 */
24
25
use XoopsModules\Wfdownloads;
26
27
require_once \dirname(__DIR__) . '/include/common.php';
28
29
/**
30
 * Class Review
31
 */
32
class Review extends \XoopsObject
33
{
34
    /**
35
     * @access public
36
     */
37
    public $helper;
38
    public $db;
39
40
    /**
41
     * @param int|null $id
42
     */
43
    public function __construct($id = null)
44
    {
45
        /** @var \XoopsModules\Wfdownloads\Helper $this ->helper */
46
        $this->helper = Helper::getInstance();
0 ignored issues
show
Bug introduced by
The property helper does not seem to exist on XoopsModules\Wfdownloads\Helper.
Loading history...
47
        $this->db     = \XoopsDatabaseFactory::getDatabaseConnection();
0 ignored issues
show
Bug introduced by
The property db does not seem to exist on XoopsModules\Wfdownloads\Helper.
Loading history...
48
        $this->initVar('review_id', \XOBJ_DTYPE_INT);
0 ignored issues
show
Bug introduced by
The method initVar() does not exist on XoopsModules\Wfdownloads\Helper. Did you maybe mean init()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

48
        $this->/** @scrutinizer ignore-call */ 
49
               initVar('review_id', \XOBJ_DTYPE_INT);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
49
        $this->initVar('lid', \XOBJ_DTYPE_INT);
50
        $this->initVar('title', \XOBJ_DTYPE_TXTBOX);
51
        $this->initVar('review', \XOBJ_DTYPE_TXTAREA);
52
        $this->initVar('submit', \XOBJ_DTYPE_INT); // boolean
53
        $this->initVar('date', \XOBJ_DTYPE_INT);
54
        $this->initVar('uid', \XOBJ_DTYPE_INT);
55
        $this->initVar('rated', \XOBJ_DTYPE_INT);
56
57
        if (null !== $id) {
58
            $item = $this->helper->getHandler('Item')->get($id);
59
            foreach ($item->vars as $k => $v) {
60
                $this->assignVar($k, $v['value']);
0 ignored issues
show
Bug introduced by
The method assignVar() does not exist on XoopsModules\Wfdownloads\Helper. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

60
                $this->/** @scrutinizer ignore-call */ 
61
                       assignVar($k, $v['value']);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
61
            }
62
        }
63
    }
64
65
    /**
66
     * @return \XoopsThemeForm
67
     */
68
    public function getForm()
69
    {
70
        require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
71
        $uid = !empty($GLOBALS['xoopsUser']) ? (int)$GLOBALS['xoopsUser']->getVar('uid') : 0;
72
73
        $form = new \XoopsThemeForm(\_AM_WFDOWNLOADS_REV_SNEWMNAMEDESC, 'reviewform', $_SERVER['REQUEST_URI']);
74
        // review: title
75
        $form->addElement(new \XoopsFormText(\_AM_WFDOWNLOADS_REV_FTITLE, 'title', 30, 40, $this->getVar('title', 'e')), true);
0 ignored issues
show
Bug introduced by
It seems like $this->getVar('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

75
        $form->addElement(new \XoopsFormText(\_AM_WFDOWNLOADS_REV_FTITLE, 'title', 30, 40, /** @scrutinizer ignore-type */ $this->getVar('title', 'e')), true);
Loading history...
76
        // review: rated
77
        $rating_select = new \XoopsFormSelect(\_AM_WFDOWNLOADS_REV_FRATING, 'rated', $this->getVar('rated'));
78
        $rating_select->addOptionArray(
79
            [
80
                '1'  => 1,
81
                '2'  => 2,
82
                '3'  => 3,
83
                '4'  => 4,
84
                '5'  => 5,
85
                '6'  => 6,
86
                '7'  => 7,
87
                '8'  => 8,
88
                '9'  => 9,
89
                '10' => 10,
90
            ]
91
        );
92
        $form->addElement($rating_select);
93
        // review: review
94
        $form->addElement(new \XoopsFormDhtmlTextArea(\_AM_WFDOWNLOADS_REV_FDESCRIPTION, 'review', $this->getVar('review', 'e'), 15, 60), true);
0 ignored issues
show
Bug introduced by
It seems like $this->getVar('review', 'e') can also be of type array and array; however, parameter $value of XoopsFormDhtmlTextArea::__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

94
        $form->addElement(new \XoopsFormDhtmlTextArea(\_AM_WFDOWNLOADS_REV_FDESCRIPTION, 'review', /** @scrutinizer ignore-type */ $this->getVar('review', 'e'), 15, 60), true);
Loading history...
95
        // form: approve
96
        $approved         = (0 == $this->getVar('submit')) ? 0 : 1;
97
        $approve_checkbox = new \XoopsFormCheckBox(\_AM_WFDOWNLOADS_REV_FAPPROVE, 'approve', $approved);
98
        $approve_checkbox->addOption(1, ' ');
99
        $form->addElement($approve_checkbox);
100
        // review: lid
101
        $form->addElement(new \XoopsFormHidden('lid', (int)$this->getVar('lid')));
102
        // review: uid
103
        $form->addElement(new \XoopsFormHidden('uid', $uid));
104
        // review: review_id
105
        $form->addElement(new \XoopsFormHidden('review_id', (int)$this->getVar('review_id')));
106
        // form: confirm
107
        $form->addElement(new \XoopsFormHidden('confirm', 1));
108
        // form: op
109
        $form->addElement(new \XoopsFormHidden('op', ''));
110
        // form: buttons
111
        $buttonTray = new \XoopsFormElementTray('', '');
112
        if ($this->isNew()) {
113
            $butt_create = new \XoopsFormButton('', '', \_AM_WFDOWNLOADS_BSAVE, 'submit');
114
            $butt_create->setExtra('onclick="this.form.elements.op.value=\'review.save\'"');
115
            $buttonTray->addElement($butt_create);
116
            $butt_clear = new \XoopsFormButton('', '', \_AM_WFDOWNLOADS_BRESET, 'reset');
117
            $buttonTray->addElement($butt_clear);
118
            $butt_cancel = new \XoopsFormButton('', '', \_AM_WFDOWNLOADS_BCANCEL, 'button');
119
            $butt_cancel->setExtra('onclick="history.go(-1)"');
120
            $buttonTray->addElement($butt_cancel);
121
        } else {
122
            $butt_create = new \XoopsFormButton('', '', \_AM_WFDOWNLOADS_BSAVE, 'submit');
123
            $butt_create->setExtra('onclick="this.form.elements.op.value=\'review.save\'"');
124
            $buttonTray->addElement($butt_create);
125
            $butt_delete = new \XoopsFormButton('', '', \_AM_WFDOWNLOADS_BDELETE, 'submit');
126
            $butt_delete->setExtra('onclick="this.form.elements.op.value=\'review.delete\'"');
127
            $buttonTray->addElement($butt_delete);
128
            $butt_cancel = new \XoopsFormButton('', '', \_AM_WFDOWNLOADS_BCANCEL, 'button');
129
            $butt_cancel->setExtra('onclick="history.go(-1)"');
130
            $buttonTray->addElement($butt_cancel);
131
        }
132
        $form->addElement($buttonTray);
133
134
        return $form;
135
    }
136
}
137