Passed
Push — master ( 4c5bd9...976bc3 )
by Michael
37s queued 10s
created

Plugin   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 47
dl 0
loc 76
rs 10
c 1
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getForm() 0 39 4
A __construct() 0 17 1
A __toString() 0 3 1
1
<?php
2
3
namespace XoopsModules\Xsitemap;
4
5
/*
6
 * ****************************************************************************
7
 * xsitemap - MODULE FOR XOOPS CMS
8
 * Copyright (c) Urbanspaceman (http://www.takeaweb.it)
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
/**
18
 * Module: xsitemap
19
 *
20
 * @package    module\Xsitemap\class
21
 * @author     XOOPS Module Development Team
22
 * @author     Urbanspaceman (http://www.takeaweb.it)
23
 * @copyright  Urbanspaceman (http://www.takeaweb.it)
24
 * @copyright  XOOPS Project (https://xoops.org)
25
 * @license    http://www.fsf.org/copyleft/gpl.html GNU public license
26
 * @link       https://xoops.org XOOPS
27
 * @since      1.00
28
 */
29
30
/**
31
 * Class Plugin
32
 */
33
class Plugin extends \XoopsObject
34
{
35
    //Constructor
36
    /**
37
     * Plugin constructor.
38
     */
39
    public function __construct()
40
    {
41
        parent::__construct();
42
        $this->initVar('plugin_id', \XOBJ_DTYPE_INT, null, false, 8);
43
        $this->initVar('plugin_name', \XOBJ_DTYPE_TXTBOX, null, false);
44
        $this->initVar('plugin_mod_version', \XOBJ_DTYPE_TXTBOX, null, false);
45
        $this->initVar('plugin_mod_table', \XOBJ_DTYPE_TXTBOX, null, false);
46
        $this->initVar('plugin_cat_id', \XOBJ_DTYPE_TXTBOX, null, false);
47
        $this->initVar('plugin_cat_pid', \XOBJ_DTYPE_TXTBOX, null, false);
48
        $this->initVar('plugin_cat_name', \XOBJ_DTYPE_TXTBOX, null, false);
49
        $this->initVar('plugin_weight', \XOBJ_DTYPE_TXTBOX, null, false);
50
        $this->initVar('plugin_call', \XOBJ_DTYPE_TXTBOX, null, false);
51
        $this->initVar('plugin_submitter', \XOBJ_DTYPE_INT, null, false, 10);
52
        $this->initVar('plugin_date_created', \XOBJ_DTYPE_INT, null, false, 10);
53
        $this->initVar('plugin_online', \XOBJ_DTYPE_INT, null, false, 1);
54
        // to allow html
55
        $this->initVar('dohtml', \XOBJ_DTYPE_INT, 1, false);
56
    }
57
58
    /**
59
     * @return string
60
     */
61
    public function __toString()
62
    {
63
        return $this->getVar('plugin_name', 's');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getVar('plugin_name', 's') also could return the type array|boolean which is incompatible with the documented return type string.
Loading history...
64
    }
65
66
    /**
67
     * @param bool $action
68
     * @return string
69
     */
70
    public function getForm($action = false)
71
    {
72
        if (false === $action) {
73
            $action = $_SERVER['REQUEST_URI'];
74
        }
75
        if ($this->isNew()) {
76
            $title               = \_AM_XSITEMAP_PLUGIN_ADD;
77
            $plugin_date_created = \time();
78
            $plugin_online       = 1;
79
        } else {
80
            $title               = \_AM_XSITEMAP_PLUGIN_EDIT;
81
            $plugin_date_created = $this->getVar('plugin_date_created');
82
            $plugin_online       = $this->getVar('plugin_online');
83
        }
84
        //            $title = $this->isNew() ? sprintf(_AM_XSITEMAP_PLUGIN_ADD) : sprintf(_AM_XSITEMAP_PLUGIN_EDIT);
85
        require_once $GLOBALS['xoops']->path('class/xoopsformloader.php');
86
        $form = new \XoopsThemeForm($title, 'form', $action, 'post', true);
87
        $form->setExtra('enctype="multipart/form-data"');
88
        $form->addElement(new \XoopsFormText(\_AM_XSITEMAP_PLUGIN_NAME, 'plugin_name', 50, 255, $this->getVar('plugin_name')), true);
0 ignored issues
show
Bug introduced by
It seems like $this->getVar('plugin_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

88
        $form->addElement(new \XoopsFormText(\_AM_XSITEMAP_PLUGIN_NAME, 'plugin_name', 50, 255, /** @scrutinizer ignore-type */ $this->getVar('plugin_name')), true);
Loading history...
89
        $form->addElement(new \XoopsFormText(\_AM_XSITEMAP_PLUGIN_MOD_VERSION, 'plugin_mod_version', 50, 255, $this->getVar('plugin_mod_version')), true);
90
        $form->addElement(new \XoopsFormText(\_AM_XSITEMAP_PLUGIN_MOD_TABLE, 'plugin_mod_table', 50, 255, $this->getVar('plugin_mod_table')), true);
91
        $form->addElement(new \XoopsFormText(\_AM_XSITEMAP_PLUGIN_CAT_ID, 'plugin_cat_id', 50, 255, $this->getVar('plugin_cat_id')), true);
92
        $form->addElement(new \XoopsFormText(\_AM_XSITEMAP_PLUGIN_CAT_PID, 'plugin_cat_pid', 50, 255, $this->getVar('plugin_cat_pid')), true);
93
        $form->addElement(new \XoopsFormText(\_AM_XSITEMAP_PLUGIN_CAT_NAME, 'plugin_cat_name', 50, 255, $this->getVar('plugin_cat_name')), true);
94
        $form->addElement(new \XoopsFormText(\_AM_XSITEMAP_PLUGIN_WEIGHT, 'plugin_weight', 50, 255, $this->getVar('plugin_weight')), true);
95
        $form->addElement(new \XoopsFormText(\_AM_XSITEMAP_PLUGIN_CALL, 'plugin_call', 50, 255, $this->getVar('plugin_call')), true);
96
        $form->addElement(new \XoopsFormSelectUser(\_AM_XSITEMAP_PLUGIN_SUBMITTER, 'plugin_submitter', false, $this->getVar('plugin_submitter'), 1, false), true);
97
        //            $plugin_date_created = $this->isNew() ? time() : $this->getVar("plugin_date_created");
98
        $form->addElement(new \XoopsFormTextDateSelect(\_AM_XSITEMAP_PLUGIN_DATE_CREATED, 'plugin_date_created', '', $plugin_date_created));
0 ignored issues
show
Bug introduced by
'' of type string is incompatible with the type integer expected by parameter $size of XoopsFormTextDateSelect::__construct(). ( Ignorable by Annotation )

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

98
        $form->addElement(new \XoopsFormTextDateSelect(\_AM_XSITEMAP_PLUGIN_DATE_CREATED, 'plugin_date_created', /** @scrutinizer ignore-type */ '', $plugin_date_created));
Loading history...
99
        //            $plugin_online = $this->isNew() ? 1 : $this->getVar("plugin_online");
100
        $check_plugin_online = new \XoopsFormCheckBox(\_AM_XSITEMAP_PLUGIN_ONLINE, 'plugin_online', $plugin_online);
101
        $check_plugin_online->addOption(1, ' ');
102
        $form->addElement($check_plugin_online);
103
        $form->addElement(new \XoopsFormHidden('op', 'save_plugin'));
104
        if (!$this->isNew()) {
105
            $form->addElement(new \XoopsFormHidden('plugin_id', $this->getVar('plugin_id')));
0 ignored issues
show
Bug introduced by
It seems like $this->getVar('plugin_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

105
            $form->addElement(new \XoopsFormHidden('plugin_id', /** @scrutinizer ignore-type */ $this->getVar('plugin_id')));
Loading history...
106
        }
107
        $form->addElement(new \XoopsFormButtonTray('submit', _SUBMIT));
108
        return $form->display();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $form->display() targeting XoopsForm::display() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
109
    }
110
}
111