Contact   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 45
dl 0
loc 74
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 26 1
A contactReplyForm() 0 19 1
A toArray() 0 9 2
1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Contact;
4
5
use XoopsObject;
6
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
12
 This program is distributed in the hope that it will be useful,
13
 but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
*/
16
17
/**
18
 * Contact module
19
 *
20
 * @copyright     XOOPS Project (https://xoops.org)
21
 * @license       https://www.fsf.org/copyleft/gpl.html GNU public license
22
 * @author        Kazumi Ono (aka Onokazu)
23
 * @author        Trabis <[email protected]>
24
 * @author        Hossein Azizabadi (AKA Voltan)
25
 * @author        Mirza (AKA Bleekk)
26
 */
27
28
/**
29
 * Class contact
30
 */
31
class Contact extends XoopsObject
32
{
33
    private $db;
34
    private $table;
35
36
    /**
37
     * contact constructor.
38
     */
39
    public function __construct()
40
    {
41
        // parent::__construct();
42
        $this->initVar('contact_id', \XOBJ_DTYPE_INT, null, false, 11);
43
        $this->initVar('contact_uid', \XOBJ_DTYPE_INT, null, false, 11);
44
        $this->initVar('contact_cid', \XOBJ_DTYPE_INT, null, false, 11);
45
        $this->initVar('contact_name', \XOBJ_DTYPE_TXTBOX, null, false);
46
        $this->initVar('contact_subject', \XOBJ_DTYPE_TXTBOX, null, false);
47
        $this->initVar('contact_mail', \XOBJ_DTYPE_EMAIL, null, false);
48
        $this->initVar('contact_url', \XOBJ_DTYPE_TXTBOX, null, false);
49
        $this->initVar('contact_create', \XOBJ_DTYPE_INT, null, false);
50
        $this->initVar('contact_icq', \XOBJ_DTYPE_TXTBOX, null, false);
51
        $this->initVar('contact_skype', \XOBJ_DTYPE_TXTBOX, null, false);
52
        $this->initVar('contact_company', \XOBJ_DTYPE_TXTBOX, null, false);
53
        $this->initVar('contact_location', \XOBJ_DTYPE_TXTBOX, null, false);
54
        $this->initVar('contact_phone', \XOBJ_DTYPE_TXTBOX, null, false);
55
        $this->initVar('contact_department', \XOBJ_DTYPE_TXTBOX, null, false);
56
        $this->initVar('contact_ip', \XOBJ_DTYPE_TXTBOX, null, false);
57
        $this->initVar('contact_message', \XOBJ_DTYPE_TXTAREA, null, false);
58
        $this->initVar('contact_address', \XOBJ_DTYPE_TXTAREA, null, false);
59
        $this->initVar('contact_reply', \XOBJ_DTYPE_INT, null, false, 1);
60
        $this->initVar('contact_platform', \XOBJ_DTYPE_ENUM, null, false, '', '', ['Android', 'Ios', 'Web']);
0 ignored issues
show
Bug introduced by
array('Android', 'Ios', 'Web') of type array<integer,string> is incompatible with the type string expected by parameter $enumerations of XoopsObject::initVar(). ( Ignorable by Annotation )

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

60
        $this->initVar('contact_platform', \XOBJ_DTYPE_ENUM, null, false, '', '', /** @scrutinizer ignore-type */ ['Android', 'Ios', 'Web']);
Loading history...
Bug introduced by
'' of type string is incompatible with the type integer expected by parameter $maxlength of XoopsObject::initVar(). ( Ignorable by Annotation )

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

60
        $this->initVar('contact_platform', \XOBJ_DTYPE_ENUM, null, false, /** @scrutinizer ignore-type */ '', '', ['Android', 'Ios', 'Web']);
Loading history...
61
        $this->initVar('contact_type', \XOBJ_DTYPE_ENUM, null, false, '', '', ['Contact', 'Phone', 'Mail']);
62
63
        $this->db    = $GLOBALS ['xoopsDB'];
64
        $this->table = $this->db->prefix('contact');
65
    }
66
67
    /**
68
     * @return \XoopsThemeForm
69
     */
70
    public function contactReplyForm(): \XoopsThemeForm
71
    {
72
        //        global $xoopsConfig;
73
        $form = new \XoopsThemeForm(_AM_CONTACT_REPLY, 'doreply', 'main.php', 'post', true);
74
        $form->setExtra('enctype="multipart/form-data"');
75
        $form->addElement(new \XoopsFormHidden('op', 'doreply'));
76
        $form->addElement(new \XoopsFormHidden('contact_id', $this->getVar('contact_id', 'e')));
0 ignored issues
show
Bug introduced by
It seems like $this->getVar('contact_id', 'e') 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

76
        $form->addElement(new \XoopsFormHidden('contact_id', /** @scrutinizer ignore-type */ $this->getVar('contact_id', 'e')));
Loading history...
77
        $form->addElement(new \XoopsFormHidden('contact_uid', $this->getVar('contact_uid', 'e')));
78
        $form->addElement(new \XoopsFormLabel(_AM_CONTACT_FROM, '', ''));
79
        $form->addElement(new \XoopsFormText(_AM_CONTACT_NAMEFROM, 'contact_name', 50, 255, \XoopsUser::getUnameFromId($GLOBALS['xoopsUser']->uid())), true);
80
        $form->addElement(new \XoopsFormText(_AM_CONTACT_MAILFROM, 'contact_mail', 50, 255, $GLOBALS['xoopsUser']->getVar('email')), true);
81
        $form->addElement(new \XoopsFormLabel(_AM_CONTACT_TO, '', ''));
82
        $form->addElement(new \XoopsFormText(_AM_CONTACT_NAMETO, 'contact_nameto', 50, 255, $this->getVar('contact_name')), true);
0 ignored issues
show
Bug introduced by
It seems like $this->getVar('contact_name') 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

82
        $form->addElement(new \XoopsFormText(_AM_CONTACT_NAMETO, 'contact_nameto', 50, 255, /** @scrutinizer ignore-type */ $this->getVar('contact_name')), true);
Loading history...
83
        $form->addElement(new \XoopsFormText(_AM_CONTACT_MAILTO, 'contact_mailto', 50, 255, $this->getVar('contact_mail')), true);
84
        $form->addElement(new \XoopsFormText(_AM_CONTACT_SUBJECT, 'contact_subject', 50, 255, _RE . $this->getVar('contact_subject')), true);
85
        $form->addElement(new \XoopsFormTextArea(_AM_CONTACT_MESSAGE, 'contact_message', '', 5, 60), true);
86
        $form->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
87
88
        return $form;
89
    }
90
91
    /**
92
     * Returns an array representation of the object
93
     *
94
     * @return array
95
     **/
96
    public function toArray()
97
    {
98
        $ret  = [];
99
        $vars = &$this->getVars();
100
        foreach (\array_keys($vars) as $i) {
101
            $ret [$i] = $this->getVar($i);
102
        }
103
104
        return $ret;
105
    }
106
}
107