Test Setup Failed
Push — master ( 9a22a9...1dbb73 )
by Michael
20:00
created

bExtcalUpcomingShow()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 76
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 37
c 1
b 0
f 0
dl 0
loc 76
rs 8.7057
cc 6
nc 5
nop 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/*
3
 * You may not change or alter any portion of this comment or credits
4
 * of supporting developers from this source code or any supporting source code
5
 * which is considered copyrighted (c) material of the original comment or credit authors.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * @copyright    {@link https://xoops.org/ XOOPS Project}
14
 * @license      {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
15
 * @package      extcal
16
 * @since
17
 * @author       XOOPS Development Team,
18
 */
19
20
use XoopsModules\Extcal\{
21
    Helper,
22
    EventHandler
23
};
24
25
require_once dirname(__DIR__) . '/include/constantes.php';
26
27
/**
28
 * @param $options
29
 *
30
 * @return array
31
 */
32
function bExtcalUpcomingShow($options)
33
{
34
    /** @var Helper $helper */
35
    if (!class_exists(Helper::class)) {
36
        return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the documented return type array.
Loading history...
37
    }
38
39
    $helper = Helper::getInstance();
40
    $helper->loadLanguage('main');
41
    $helper->loadLanguage('blocks');
42
43
    $eventHandler = $helper->getHandler(_EXTCAL_CLN_EVENT);
44
45
    $nbEvent     = $options[0];
46
    $titleLenght = $options[1];
0 ignored issues
show
Unused Code introduced by
The assignment to $titleLenght is dead and can be removed.
Loading history...
47
    $nbDays      = $options[2];
48
49
    array_shift($options);
50
    array_shift($options);
51
    array_shift($options);
52
53
    // Checking if no cat is selected
54
    if (isset($options[0]) && 0 == $options[0] && 1 == count($options)) {
55
        $options = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $options is dead and can be removed.
Loading history...
56
    }
57
58
    //-------------------
59
    /* ========================================================================== */
60
    $year  = \Xmf\Request::getInt('year', date('Y'), 'GET');
0 ignored issues
show
Bug introduced by
date('Y') of type string is incompatible with the type integer expected by parameter $default of Xmf\Request::getInt(). ( Ignorable by Annotation )

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

60
    $year  = \Xmf\Request::getInt('year', /** @scrutinizer ignore-type */ date('Y'), 'GET');
Loading history...
61
    $month = \Xmf\Request::getInt('month', date('n'), 'GET');
62
    $day   = \Xmf\Request::getInt('day', date('j'), 'GET');
63
    $cat   = \Xmf\Request::getInt('cat', 0, 'GET');
64
    /* ========================================================================== */
65
66
    // Validate the date (day, month and year)
67
    $dayTS = mktime(0, 0, 0, $month, $day, $year);
68
69
    //$offset = $helper->getConfig('week_start_day') - date('w', $dayTS);
70
71
    //------- mb --------------
72
    //   let's make sure that the upcoming events start tomorrow
73
    //    $offset = date('w', $dayTS) + 7-$helper->getConfig('week_start_day')<7 ? date('w', $dayTS) + 7-$helper->getConfig('week_start_day') : 0;
74
    //    $dayTS = $dayTS - ($offset * _EXTCAL_TS_DAY);
75
76
    $dayTS += _EXTCAL_TS_DAY;
77
    //------- mb -----------------
78
79
    $year  = date('Y', $dayTS);
80
    $month = date('n', $dayTS);
81
    $day   = date('j', $dayTS);
82
83
    // Retriving events and formatting them
84
    //$events = $eventHandler->objectToArray($eventHandler->getEventWeek($day, $month, $year, $cat), array('cat_id'));
85
    $criteres = [
86
        'periode'      => _EXTCAL_EVENTS_UPCOMING,
87
        //        'periode'      => _EXTCAL_EVENTS_CALENDAR_WEEK,
88
        'day'          => $day,
89
        'month'        => $month,
90
        'year'         => $year,
91
        'cat'          => $cat,
92
        'externalKeys' => 'cat_id',
93
        'nbEvent'      => $nbEvent,
94
        'nbDays'       => $nbDays,
95
    ];
96
    $events   = $eventHandler->getEventsOnPeriode($criteres);
0 ignored issues
show
Bug introduced by
The method getEventsOnPeriode() 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

96
    /** @scrutinizer ignore-call */ 
97
    $events   = $eventHandler->getEventsOnPeriode($criteres);
Loading history...
97
98
    //----------------------------
99
100
    //$eventHandler->serverTimeToUserTimes($events);
101
    $eventHandler->formatEventsDate($events, $helper->getConfig('event_date_month'));
0 ignored issues
show
Bug introduced by
The method formatEventsDate() 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

101
    $eventHandler->/** @scrutinizer ignore-call */ 
102
                   formatEventsDate($events, $helper->getConfig('event_date_month'));
Loading history...
102
103
    if (count($events) > $nbEvent) {
104
        $events = array_slice($events, 0, $nbEvent);
0 ignored issues
show
Bug introduced by
It seems like $events can also be of type null; however, parameter $array of array_slice() does only seem to accept array, 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

104
        $events = array_slice(/** @scrutinizer ignore-type */ $events, 0, $nbEvent);
Loading history...
105
    }
106
107
    return $events;
108
}
109
110
/**
111
 * @param $options
112
 *
113
 * @return string
114
 */
115
function bExtcalUpcomingEdit($options)
116
{
117
    global $xoopsUser;
118
119
    /** @var Helper $helper */
120
    if (!class_exists(Helper::class)) {
121
        return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the documented return type string.
Loading history...
122
    }
123
124
    $helper = Helper::getInstance();
125
    $helper->loadLanguage('main');
126
    $helper->loadLanguage('blocks');
127
    $categoryHandler = $helper->getHandler(_EXTCAL_CLN_CAT);
128
129
    $cats = $categoryHandler->getAllCat($xoopsUser, 'extcal_cat_view');
0 ignored issues
show
Bug introduced by
The method getAllCat() 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

129
    /** @scrutinizer ignore-call */ 
130
    $cats = $categoryHandler->getAllCat($xoopsUser, 'extcal_cat_view');
Loading history...
130
131
    $form = _MB_EXTCAL_DISPLAY . "&nbsp;\n";
132
    $form .= '<input name="options[0]" size="5" maxlength="255" value="' . $options[0] . '" type="text">&nbsp;' . _MB_EXTCAL_EVENT . '<br>';
133
    $form .= _MB_EXTCAL_TITLE_LENGTH . ' : <input name="options[1]" size="5" maxlength="255" value="' . $options[1] . '" type="text"><br>';
134
135
    $form .= _MB_EXTCAL_UPCOMING_DAYS . ' : <input name="options[2]" size="5" maxlength="255" value="' . $options[2] . '" type="text"><br>';
136
137
    array_shift($options);
138
    array_shift($options);
139
    array_shift($options);
140
141
    $form .= _MB_EXTCAL_CAT_TO_USE . '<br><select name="options[]" multiple="multiple" size="5">';
142
    if (false === array_search(0, $options, true)) {
143
        $form .= '<option value="0">' . _MB_EXTCAL_ALL_CAT . '</option>';
144
    } else {
145
        $form .= '<option value="0" selected="selected">' . _MB_EXTCAL_ALL_CAT . '</option>';
146
    }
147
    foreach ($cats as $cat) {
148
        if (false === array_search($cat->getVar('cat_id'), $options, true)) {
149
            $form .= '<option value="' . $cat->getVar('cat_id') . '">' . $cat->getVar('cat_name') . '</option>';
150
        } else {
151
            $form .= '<option value="' . $cat->getVar('cat_id') . '" selected="selected">' . $cat->getVar('cat_name') . '</option>';
152
        }
153
    }
154
    $form .= '</select>';
155
156
    return $form;
157
}
158