Passed
Push — master ( c41a18...3e0550 )
by Goffy
30s queued 12s
created

XoopspollFormDateTimePicker   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 85
rs 10
c 0
b 0
f 0
wmc 9
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A FormDateTimePicker::__construct() 0 6 5
1
<?php
2
3
namespace XoopsModules\Xoopspoll;
4
5
/**
6
 * Xoopspoll form timepicker
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
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 *
15
 * @copyright ::   &copy; {@link https://xoops.org/ XOOPS Project}
16
 * @license   ::     {@link https://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU GPL 2}
17
 * @package   ::     xoopspoll
18
 * @subpackage::  class
19
 * @since     ::       1.40
20
 * @author    ::      TXMod Xoops (aka timgno) {@link http://www.txmodxoops.org/ TXMod Xoops}
21
 * @author    ::      zyspec <[email protected]>
22
 * @credits::     {@link http://www.trentrichardson.com Trent Richardson}
23
 */
24
25
26
27
/**
28
 * Creates a text field with jquery ui calendar & time select popup
29
 */
30
class FormDateTimePicker extends \XoopsFormText
31
{
32
    /**
33
     * Contains the maximum field size
34
     */
35
    public const MAXSIZE = 25;
36
37
    /**
38
     * Constructor to build FormDateTimePicker object
39
     * @param mixed $caption HTML description to display for the element
40
     * @param mixed $name    HTML element name (ie. name='$name')
41
     * @param mixed $size    size of field to display
42
     * @param mixed $value   timestamp of date/time to show
43
     */
44
    public function __construct($caption, $name, $size, $value)
45
    {
46
        $value = (!\is_numeric($value) || (0 === (int)$value)) ? \time($value) : (int)$value;
0 ignored issues
show
Unused Code introduced by
The call to time() has too many arguments starting with $value. ( Ignorable by Annotation )

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

46
        $value = (!\is_numeric($value) || (0 === (int)$value)) ? /** @scrutinizer ignore-call */ \time($value) : (int)$value;

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
Unused Code introduced by
The call to time() has too many arguments starting with $value. ( Ignorable by Annotation )

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

46
        $value = (!\is_numeric($value) || (0 === (int)$value)) ? /** @scrutinizer ignore-call */ \time($value) : (int)$value;

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
47
        $size  = (int)$size;
48
        $size  = ($size > 0 && $size <= self::MAXSIZE) ? $size : self::MAXSIZE;
49
        parent::__construct($caption, $name, $size, self::MAXSIZE, $value);
50
    }
51
52
    /**
53
     * Generate the HTML <input> to display the date/time field
54
     * @return string HTML code used to display in a form
55
     */
56
    public function render()
57
    {
58
        static $included = false;
59
60
        $ele_name  = $this->getName();
61
        $ele_value = $this->getValue(true);
62
        //        if (is_string($ele_value)) {
63
        if (!\is_numeric($ele_value)) {
64
            $display_value = $ele_value;
65
            $ele_value     = \time();
0 ignored issues
show
Unused Code introduced by
The assignment to $ele_value is dead and can be removed.
Loading history...
Unused Code introduced by
The assignment to $ele_value is dead and can be removed.
Loading history...
66
        } else {
67
            //            $display_value = '';
68
            //            $display_value = formatTimestamp($ele_value, 'm');
69
            $display_value = \ucfirst(\date(_MEDIUMDATESTRING, $ele_value));
0 ignored issues
show
Bug introduced by
$ele_value of type string is incompatible with the type integer expected by parameter $timestamp of date(). ( Ignorable by Annotation )

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

69
            $display_value = \ucfirst(\date(_MEDIUMDATESTRING, /** @scrutinizer ignore-type */ $ele_value));
Loading history...
Bug introduced by
$ele_value of type string is incompatible with the type integer expected by parameter $timestamp of date(). ( Ignorable by Annotation )

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

69
            $display_value = \ucfirst(\date(_MEDIUMDATESTRING, /** @scrutinizer ignore-type */ $ele_value));
Loading history...
70
        }
71
72
        if (\is_object($GLOBALS['xoTheme'])) {
73
            $moduleHandler = \xoops_getHandler('module');
74
            $sys_module    = $moduleHandler->getByDirname('system');
0 ignored issues
show
Bug introduced by
The method getByDirname() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsModuleHandler or XoopsPersistableObjectHandler. ( Ignorable by Annotation )

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

74
            /** @scrutinizer ignore-call */ 
75
            $sys_module    = $moduleHandler->getByDirname('system');
Loading history...
Bug introduced by
The method getByDirname() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsModuleHandler or XoopsPersistableObjectHandler. ( Ignorable by Annotation )

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

74
            /** @scrutinizer ignore-call */ 
75
            $sys_module    = $moduleHandler->getByDirname('system');
Loading history...
75
            $configHandler = \xoops_getHandler('config');
76
            $moduleConfig  = $configHandler->getConfigsByCat(0, $sys_module->getVar('mid'));
0 ignored issues
show
Bug introduced by
The method getConfigsByCat() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler. ( Ignorable by Annotation )

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

76
            /** @scrutinizer ignore-call */ 
77
            $moduleConfig  = $configHandler->getConfigsByCat(0, $sys_module->getVar('mid'));
Loading history...
Bug introduced by
The method getConfigsByCat() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler. ( Ignorable by Annotation )

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

76
            /** @scrutinizer ignore-call */ 
77
            $moduleConfig  = $configHandler->getConfigsByCat(0, $sys_module->getVar('mid'));
Loading history...
77
            $jq_theme_dir  = $moduleConfig['jquery_theme'];
78
79
            $GLOBALS['xoTheme']->addStylesheet($GLOBALS['xoops']->url("modules/system/css/ui/{$jq_theme_dir}/ui.all.css"));
80
            $GLOBALS['xoTheme']->addScript('browse.php?Frameworks/jquery/jquery.js');
81
            $GLOBALS['xoTheme']->addScript('browse.php?Frameworks/jquery/plugins/jquery.ui.js');
82
            $GLOBALS['xoTheme']->addScript('browse.php?modules/xoopspoll/assets/js/jquery-ui-timepicker-addon.js');
83
            $GLOBALS['xoTheme']->addScript('browse.php?modules/xoopspoll/assets/js/jquery-ui-sliderAccess.js');
84
            $GLOBALS['xoTheme']->addStylesheet($GLOBALS['xoops']->url('modules/xoopspoll/assets/css/datetimepicker.css'));
85
86
            if (!$included) {
87
                $included = true;
88
                \xoops_loadLanguage('admin', 'xoopspoll');
89
                // setup regional date variables
90
                $reg_values = "closeText: '"
91
                              . \_AM_XOOPSPOLL_DTP_CLOSETEXT
92
                              . "',"
93
                              . "prevText: '"
94
                              . \_AM_XOOPSPOLL_DTP_PREVTEXT
95
                              . "',"
96
                              . "nextText: '"
97
                              . \_AM_XOOPSPOLL_DTP_NEXTTEXT
98
                              . "',"
99
                              . "currentText: '"
100
                              . \_AM_XOOPSPOLL_DTP_CURRENTTEXT
101
                              . "',"
102
                              . 'monthNames: ['
103
                              . \_AM_XOOPSPOLL_DTP_MONTHNAMES
104
                              . '],'
105
                              . 'monthNamesShort: ['
106
                              . \_AM_XOOPSPOLL_DTP_MONTHNAMESSHORT
107
                              . '],'
108
                              . 'dayNames: ['
109
                              . \_AM_XOOPSPOLL_DTP_DAYNAMES
110
                              . '],'
111
                              . 'dayNamesShort: ['
112
                              . \_AM_XOOPSPOLL_DTP_DAYNAMESSHORT
113
                              . '],'
114
                              . 'dayNamesMin: ['
115
                              . \_AM_XOOPSPOLL_DTP_DAYNAMESMIN
116
                              . '],'
117
                              . "weekHeader: '"
118
                              . \_AM_XOOPSPOLL_DTP_WEEKHEADER
119
                              . "',"
120
                              . "dateFormat: '"
121
                              . \_AM_XOOPSPOLL_DTP_DATEFORMAT
122
                              . "',"
123
                              . "firstDay: '"
124
                              . \_AM_XOOPSPOLL_DTP_FIRSTDAY
125
                              . "',"
126
                              . 'isRTL: '
127
                              . \_AM_XOOPSPOLL_DTP_ISRTL
128
                              . ','
129
                              . 'showMonthAfterYear: '
130
                              . \_AM_XOOPSPOLL_DTP_SHOWMONTHAFTERYEAR
131
                              . ','
132
                              . "yearSuffix: '"
133
                              . \_AM_XOOPSPOLL_DTP_YEARSUFFIX
134
                              . "',";
135
                // set regional time variables
136
                $reg_values .= "timeOnlyTitle: '"
137
                               . \_AM_XOOPSPOLL_DTP_TIMEONLYTITLE
138
                               . "',"
139
                               . "timeText: '"
140
                               . \_AM_XOOPSPOLL_DTP_TIMETEXT
141
                               . "',"
142
                               . "hourText: '"
143
                               . \_AM_XOOPSPOLL_DTP_HOURTEXT
144
                               . "',"
145
                               . "minuteText: '"
146
                               . \_AM_XOOPSPOLL_DTP_MINUTETEXT
147
                               . "',"
148
                               . "secondText: '"
149
                               . \_AM_XOOPSPOLL_DTP_SECONDTEXT
150
                               . "',"
151
                               . "millisecText: '"
152
                               . \_AM_XOOPSPOLL_DTP_MILLISECTEXT
153
                               . "',"
154
                               . "timeFormat: '"
155
                               . \_AM_XOOPSPOLL_DTP_TIMEFORMAT
156
                               . "',"
157
                               . 'ampm: false,'
158
                               . 'stepMinute: 5';
159
160
                $GLOBALS['xoTheme']->addScript(
161
                    '',
162
                    '',
163
                    '
164
                  $(function() {
165
                      $( ".datetimepicker" ).datetimepicker({
166
                          ' . $reg_values . '
167
                      });
168
                  });
169
        '
170
                );
171
            }
172
        }
173
174
        return "<input type='text' name='{$ele_name}' id='{$ele_name}' class='datetimepicker' size='" . $this->getSize() . "' maxlength='" . $this->getMaxlength() . "' value='{$display_value}'" . $this->getExtra() . '>';
175
    }
176
}
177