Completed
Push — master ( 55a138...ee7aee )
by Michael
05:41
created

EventHandler::getOccurTS()   D

Complexity

Conditions 108
Paths 143

Size

Total Lines 558
Code Lines 368

Duplication

Lines 504
Ratio 90.32 %

Importance

Changes 0
Metric Value
cc 108
eloc 368
nc 143
nop 3
dl 504
loc 558
rs 4
c 0
b 0
f 0

How to fix   Long Method    Complexity   

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 namespace XoopsModules\Extcal;
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 31 and the first side effect is on line 26.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
/*
4
 * You may not change or alter any portion of this comment or credits
5
 * of supporting developers from this source code or any supporting source code
6
 * which is considered copyrighted (c) material of the original comment or credit authors.
7
 *
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
13
/**
14
 * @copyright    {@link https://xoops.org/ XOOPS Project}
15
 * @license      {@link http://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
16
 * @package      extcal
17
 * @since
18
 * @author       XOOPS Development Team,
19
 */
20
21
//use Punic\Exception;
22
use XoopsModules\Extcal;
23
24
// defined('XOOPS_ROOT_PATH') || exit('Restricted access.');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
25
26
require_once __DIR__ . '/../include/constantes.php';
27
28
/**
29
 * Class EventHandler.
30
 */
31
class EventHandler extends ExtcalPersistableObjectHandler
32
{
33
    private $_extcalPerm;
34
    private $_extcalTime;
35
    private $_extcalConfig;
0 ignored issues
show
Unused Code introduced by
The property $_extcalConfig is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
36
37
    /**
38
     * @param $db
39
     */
40
    public function __construct(\XoopsDatabase $db)
41
    {
42
        $this->_extcalPerm = Extcal\Perm::getHandler();
43
        $this->_extcalTime = Extcal\Time::getHandler();
44
        //         $extcalConfig = Extcal\Config::getHandler();
0 ignored issues
show
Unused Code Comprehensibility introduced by
46% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
45
        //         $this->_extcalConfig = $extcalConfig->getModuleConfig();
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
46
        parent::__construct($db, 'extcal_event', Event::class, 'event_id');
47
    }
48
49
    /**
50
     * @param $data
51
     *
52
     * @return bool
53
     */
54 View Code Duplication
    public function createEvent($data)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55
    {
56
        $event = $this->create();
57
        $this->checkDate($data);
58
        $this->userTimeToServerTime($data);
59
        $this->addRecurValue($data);
60
        $event->setVars($data);
61
62
        return $this->insert($event, true);
63
    }
64
65
    /**
66
     * @param $data
67
     *
68
     * @return \XoopsObject
69
     */
70
    public function createEventForPreview($data)
71
    {
72
        $event = $this->create();
73
        $this->checkDate($data);
74
        $this->addRecurValue($data);
75
        $event->setVars($data);
76
77
        return $event;
78
    }
79
80
    /**
81
     * @param $eventId
82
     * @param $data
83
     *
84
     * @return bool
85
     */
86 View Code Duplication
    public function modifyEvent($eventId, $data)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
87
    {
88
        $event = $this->get($eventId);
89
        $this->checkDate($data);
90
        $this->userTimeToServerTime($data);
91
        $this->addRecurValue($data);
92
        $event->setVars($data);
93
94
        return $this->insert($event);
95
    }
96
97
    /**
98
     * @param $eventId
99
     */
100
    public function deleteEvent($eventId)
101
    {
102
        /* TODO :
103
           - Delete who's going
104
           - Delete who's not going
105
           - Delete comment
106
           - Delete notifications
107
          */
108
        $this->deleteById($eventId, true);
109
    }
110
111
    /**
112
     * @param null $criteria
113
     * @param bool $force
114
     * @param bool $asObject
115
     */
116
    public function deleteAllEvents($criteria = null, $force = true, $asObject = false)
117
    {
118
        /* TODO :
119
           - Delete who's going
120
           - Delete who's not going
121
           - Delete comment
122
           - Delete notifications
123
          */
124
        $this->deleteAll($criteria, $force, $asObject);
125
    }
126
127
    /**
128
     * @param null $criteria
129
     * @param bool $asObject
130
     *
131
     * @return array
132
     */
133
    public function getAllEvents($criteria = null, $asObject = false)
134
    {
135
        $rst = $this->getObjects($criteria, $asObject);
136
        if ($asObject) {
137
            return $rst;
138
        } else {
139
            return $this->objectToArray($rst);
140
        }
141
    }
142
143
    // Return one approved event selected by his id
144
145
    /**
146
     * @param      $eventId
147
     * @param bool $skipPerm
148
     *
149
     * @return bool
150
     */
151 View Code Duplication
    public function getEvent($eventId, $skipPerm = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
getEvent uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
152
    {
153
        $user = $GLOBALS['xoopsUser'];
154
155
        $criteriaCompo = new \CriteriaCompo();
156
        $criteriaCompo->add(new \Criteria('event_id', $eventId));
157
        $criteriaCompo->add(new \Criteria('event_approved', 1));
158
        if (!$skipPerm) {
159
            $this->addCatPermCriteria($criteriaCompo, $user);
160
        }
161
        $ret = $this->getObjects($criteriaCompo);
162
        if (isset($ret[0])) {
163
            return $ret[0];
164
        } else {
165
            return false;
166
        }
167
    }
168
169
    // Return one event selected by his id (approve or not)
170
171
    /**
172
     * @param      $eventId
173
     * @param bool $skipPerm
174
     *
175
     * @return bool
176
     */
177 View Code Duplication
    public function getEventWithNotApprove($eventId, $skipPerm = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
getEventWithNotApprove uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
178
    {
179
        $user = $GLOBALS['xoopsUser'];
180
181
        $criteriaCompo = new \CriteriaCompo();
182
        $criteriaCompo->add(new \Criteria('event_id', $eventId));
183
        if (!$skipPerm) {
184
            $this->addCatPermCriteria($criteriaCompo, $user);
185
        }
186
        $ret = $this->getObjects($criteriaCompo);
187
        if (isset($ret[0])) {
188
            return $ret[0];
189
        } else {
190
            return false;
191
        }
192
    }
193
194
    /**
195
     * @param $events
196
     * @param $pattern
197
     */
198
    public function formatEventsDate(&$events, $pattern)
199
    {
200
        //        $max = count($events);
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
201
        //        for ($i = 0; $i < $max; ++$i) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
202
        //            $this->formatEventDate($events[$i], $pattern);
0 ignored issues
show
Unused Code Comprehensibility introduced by
79% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
203
        //        }
204
        foreach ($events as $i => $iValue) {
205
            $this->formatEventDate($events[$i], $pattern);
206
        }
207
    }
208
209
    //  function getPicture1(&$event) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
210
    //      return $event['event_picture1'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
211
    //  }
212
    //  function getPicture2(&$event) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
213
    //      return $event['event_picture2'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
214
    //  }
215
    //  function getDesc(&$event) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
216
    //      return $event['event_desc'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
217
    //  }
218
219
    /**
220
     * @param $event
221
     * @param $pattern
222
     */
223
    public function formatEventDate(&$event, $pattern)
224
    {
225
        if (!$event['event_isrecur']) {
226
            $event['formated_event_start'] = $this->_extcalTime->getFormatedDate($pattern, $event['event_start']);
227
            $event['formated_event_end']   = $this->_extcalTime->getFormatedDate($pattern, $event['event_end']);
228
        } else {
229
            $event['formated_event_start'] = $this->_extcalTime->getFormatedDate($pattern, $event['event_start']);
230
            $event['formated_event_end']   = $this->_extcalTime->getFormatedDate($pattern, $event['event_end']);
231
            $event['formated_reccur_rule'] = $this->_extcalTime->getFormatedReccurRule($event['event_recur_rules']);
232
        }
233
        $event['formated_event_submitdate'] = $this->_extcalTime->getFormatedDate($pattern, $event['event_submitdate']);
234
    }
235
236
    //JJD - to valid modif
237
    //     function checkDate(&$data)
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
238
    //     {
239
    //
240
    //         list($year, $month, $day) = explode("-", $data['event_start']['date']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
241
    //         $data['event_start']
242
    //             =
243
    //             mktime(0, 0, 0, $month, $day, $year) + $data['event_start']['time'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
68% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
244
    //         list($year, $month, $day) = explode("-", $data['event_end']['date']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
245
    //         $data['event_end']
246
    //             = mktime(0, 0, 0, $month, $day, $year) + $data['event_end']['time'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
247
    //
248
    //         if ($data['have_end'] == 0 || $data['event_start'] > $data['event_end']
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
249
    //) {
250
    //             $data['event_end'] = $data['event_start'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
251
    //         }
252
    //
253
    //     }
254
255
    /**
256
     * @param $data
257
     */
258
    public function checkDate(&$data)
259
    {
260
        $data['event_start'] = strtotime($data['event_start']['date']) + $data['event_start']['time'];
261
        $data['event_end']   = strtotime($data['event_end']['date']) + $data['event_end']['time'];
262
263
        if (0 == $data['have_end'] || $data['event_start'] > $data['event_end']) {
264
            $data['event_end'] = $data['event_start'];
265
        }
266
    }
267
268
    /**
269
     * @param $data
270
     */
271
    private function userTimeToServerTime(&$data)
0 ignored issues
show
Coding Style introduced by
userTimeToServerTime uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
272
    {
273
        $user = $GLOBALS['xoopsUser'];
274
275
        $data['event_start'] = userTimeToServerTime($data['event_start'], $this->_extcalTime->_getUserTimeZone($user));
0 ignored issues
show
Bug introduced by
The method _getUserTimeZone() does not exist on XoopsModules\Extcal\Time. Did you maybe mean getUserTimeZone()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
276
        $data['event_end']   = userTimeToServerTime($data['event_end'], $this->_extcalTime->_getUserTimeZone($user));
0 ignored issues
show
Bug introduced by
The method _getUserTimeZone() does not exist on XoopsModules\Extcal\Time. Did you maybe mean getUserTimeZone()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
277
    }
278
279
    /**
280
     * @param $data
281
     */
282
    public function serverTimeToUserTime(&$data)
0 ignored issues
show
Coding Style introduced by
serverTimeToUserTime uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
283
    {
284
        $user = $GLOBALS['xoopsUser'];
285
286
        $data['event_start']      = xoops_getUserTimestamp($data['event_start'], $this->_extcalTime->_getUserTimeZone($user));
0 ignored issues
show
Bug introduced by
The method _getUserTimeZone() does not exist on XoopsModules\Extcal\Time. Did you maybe mean getUserTimeZone()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
287
        $data['event_end']        = xoops_getUserTimestamp($data['event_end'], $this->_extcalTime->_getUserTimeZone($user));
0 ignored issues
show
Bug introduced by
The method _getUserTimeZone() does not exist on XoopsModules\Extcal\Time. Did you maybe mean getUserTimeZone()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
288
        $data['event_submitdate'] = xoops_getUserTimestamp($data['event_submitdate'], $this->_extcalTime->_getUserTimeZone($user));
0 ignored issues
show
Bug introduced by
The method _getUserTimeZone() does not exist on XoopsModules\Extcal\Time. Did you maybe mean getUserTimeZone()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
289
    }
290
291
    /**
292
     * @param $events
293
     */
294
    public function serverTimeToUserTimes(&$events)
295
    {
296
        foreach ($events as $i => $iValue) {
297
            $this->serverTimeToUserTime($events[$i]);
298
        }
299
    }
300
301
    /**
302
     * @param $data
303
     */
304
    public function addRecurValue(&$data)
0 ignored issues
show
Coding Style introduced by
addRecurValue uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
305
    {
306
        $data['event_isrecur']     = $this->getIsRecur($_POST);
307
        $data['event_recur_rules'] = $this->getRecurRules($_POST);
308
        $data['event_recur_start'] = $this->getRecurStart($data, $_POST);
309
        $data['event_recur_end']   = $this->getRecurEnd($data, $_POST);
310
    }
311
312
    /***************************************************************
313
     * Return events on perioe
314
     **************************************************************
315
     *
316
     * @param $criteres
317
     *
318
     * @return array
319
     */
320
    public function getEventsOnPeriode($criteres)
321
    {
322
        //Extcal\Utility::echoArray($criteres);
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
323
        global $extcalConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
324
        $myts = \MyTextSanitizer::getInstance(); // MyTextSanitizer object
0 ignored issues
show
Unused Code introduced by
$myts is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
325
326
        $eventsU = $this->getEventsUniques($criteres);
327
        $eventsR = $this->getEventsRecurents($criteres);
328
        $events  = array_merge($eventsU, $eventsR);
329
330
        //      $events = $eventsU;
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
331
332
        //Extcal\Utility::echoArray($events);
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
333
334
        //Tri des evennement par date ascendante
335
        $ordre      = [];
336
        $eventArray = [];
337
338
        //        while (list($k, $v) = each($events)) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
339
        foreach ($events as $k => $v) {
340
            $ordre[] = (int)$v['event_start'];
341
            $this->formatEventDate($v, $extcalConfig['event_date_week']);
342
            //$v['cat']['cat_light_color'] = $v['cat']['cat_color'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
343
            $v['cat']['cat_light_color'] = Extcal\Utility::getLighterColor($v['cat']['cat_color'], _EXTCAL_INFOBULLE_RGB_MIN, _EXTCAL_INFOBULLE_RGB_MAX);
344
            if ('' == $v['event_icone']) {
345
                $v['event_icone'] = $v['cat']['cat_icone'];
346
            }
347
            $v['event_desc'] = html_entity_decode($v['event_desc']);
348
            $eventArray[]    = $v;
349
        }
350
        array_multisort($eventArray, SORT_ASC, SORT_NUMERIC, $ordre, SORT_ASC, SORT_NUMERIC);
351
352
        return $eventArray;
353
    }
354
355
    /*****************************************************************
356
     *
357
     ****************************************************************
358
     * @param $criteres
359
     * @return array
360
     */
361
    public function getEventsUniques($criteres)
362
    {
363
        $cat = 0;
364
        global $extcalConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
365
        //        while (list($k, $v) = each($criteres)) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
366
        foreach ($criteres as $k => $v) {
367
            $$k = $v;
368
        }
369
        if (!isset($nbDays)) {
0 ignored issues
show
Bug introduced by
The variable $nbDays seems only to be defined at a later point. As such the call to isset() seems to always evaluate to false.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
370
            $nbDays = 7;
371
        }
372
        if (!isset($sens)) {
0 ignored issues
show
Bug introduced by
The variable $sens seems only to be defined at a later point. As such the call to isset() seems to always evaluate to false.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
373
            $sens = 'ASC';
374
        }
375
        if (!isset($externalKeys)) {
0 ignored issues
show
Bug introduced by
The variable $externalKeys seems only to be defined at a later point. As such the call to isset() seems to always evaluate to false.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
376
            $externalKeys = ['cat_id'];
377
        }
378
        //------------------------------------------------------
379
        switch ($periode) {
0 ignored issues
show
Bug introduced by
The variable $periode does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
380
381
            case _EXTCAL_EVENTS_CALENDAR_WEEK:
382
                $criteriaCompo = $this->_getEventWeekCriteria($day, $month, $year, $cat, $nbDays);
0 ignored issues
show
Bug introduced by
The variable $day does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $month does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $year does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
383
                if (!$extcalConfig['diplay_past_event_cal']) {
384
                    $criteriaCompo->add(new \Criteria('event_end', time(), '>'));
385
                }
386
                break;
387
388
            case _EXTCAL_EVENTS_WEEK:
389 View Code Duplication
            case _EXTCAL_EVENTS_AGENDA_WEEK:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
390
                $criteriaCompo = $this->_getEventWeekCriteria($day, $month, $year, $cat, $nbDays);
391
                if (!$extcalConfig['diplay_past_event_list']) {
392
                    $criteriaCompo->add(new \Criteria('event_end', time(), '>'));
393
                }
394
                break;
395
396 View Code Duplication
            case _EXTCAL_EVENTS_CALENDAR_MONTH:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
397
                $criteriaCompo = $this->_getEventMonthCriteria($month, $year, $cat);
398
399
                if (!$extcalConfig['diplay_past_event_cal']) {
400
                    $criteriaCompo->add(new \Criteria('event_end', time(), '>'));
401
                }
402
                break;
403
404 View Code Duplication
            case _EXTCAL_EVENTS_MONTH:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
405
                $criteriaCompo = $this->_getEventMonthCriteria($month, $year, $cat);
406
407
                if (!$extcalConfig['diplay_past_event_list']) {
408
                    $criteriaCompo->add(new \Criteria('event_end', time(), '>'));
409
                }
410
                break;
411
412
            case _EXTCAL_EVENTS_DAY:
413
                $criteriaCompo = $this->_getEventDayCriteria($day, $month, $year, $cat);
414
415
                break;
416
417
            case _EXTCAL_EVENTS_YEAR:
418
                $criteriaCompo = $this->_getEventYearCriteria($year, $cat);
419
                break;
420
421
            case _EXTCAL_EVENTS_UPCOMING:
422
                $criteriaCompo = $this->_getEventWeekCriteria($day, $month, $year, $cat, $nbDays);
423
                break;
424
425
        }
426
        //--------------------------------------------------------------------------
427
        $criteriaCompo->add(new \Criteria('event_isrecur', 0, '='));
0 ignored issues
show
Bug introduced by
The variable $criteriaCompo does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
428
        $criteriaCompo->setOrder($sens);
429
430
        $result = $this->getObjects($criteriaCompo);
431
        $events = $this->objectToArray($result, $externalKeys);
432
        $this->serverTimeToUserTimes($events);
433
434
        return $events;
435
    }
436
437
    /*****************************************************************
438
     * evennement récurents
439
     ****************************************************************
440
     * @param $criteres
441
     * @return array
442
     */
443
444
    public function getEventsRecurents($criteres)
0 ignored issues
show
Coding Style introduced by
getEventsRecurents uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
445
    {
446
        global $extcalConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
447
448
        //        while (list($k, $v) = each($criteres)) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
449
        foreach ($criteres as $k => $v) {
450
            $$k = $v;
451
        }
452
        if (!isset($nbDays)) {
0 ignored issues
show
Bug introduced by
The variable $nbDays seems only to be defined at a later point. As such the call to isset() seems to always evaluate to false.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
453
            $nbDays = 7;
454
        }
455
        if (!isset($sens)) {
0 ignored issues
show
Bug introduced by
The variable $sens seems only to be defined at a later point. As such the call to isset() seems to always evaluate to false.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
456
            $sens = 'ASC';
457
        }
458
        if (!isset($externalKeys)) {
0 ignored issues
show
Bug introduced by
The variable $externalKeys seems only to be defined at a later point. As such the call to isset() seems to always evaluate to false.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
459
            $externalKeys = ['cat_id'];
460
        }
461
        $user = $GLOBALS['xoopsUser'];
462
        //------------------------------------------------------
463
464
        $criteriaCompo = new \CriteriaCompo();
465
466
        switch ($periode) {
0 ignored issues
show
Bug introduced by
The variable $periode does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
467
            case _EXTCAL_EVENTS_WEEK:
468
            case _EXTCAL_EVENTS_CALENDAR_WEEK:
469
            case _EXTCAL_EVENTS_AGENDA_WEEK:
470 View Code Duplication
            case _EXTCAL_EVENTS_UPCOMING:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
471
                $start = userTimeToServerTime(mktime(0, 0, 0, $month, $day, $year), $this->_extcalTime->_getUserTimeZone($user));
0 ignored issues
show
Bug introduced by
The variable $month does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $day does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $year does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The method _getUserTimeZone() does not exist on XoopsModules\Extcal\Time. Did you maybe mean getUserTimeZone()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
472
                $end   = userTimeToServerTime(mktime(0, 0, 0, $month, $day + $nbDays + 1, $year), $this->_extcalTime->_getUserTimeZone($user));
0 ignored issues
show
Bug introduced by
The method _getUserTimeZone() does not exist on XoopsModules\Extcal\Time. Did you maybe mean getUserTimeZone()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
473
                //$end = $start + (($nbDays + 1 )* _EXTCAL_TS_DAY);
0 ignored issues
show
Unused Code Comprehensibility introduced by
41% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
474
                //$end = userTimeToServerTime(mktime(0, 0, 0, $month, $day+(($nbJours)+1 * _EXTCAL_TS_DAY), $year), $this->_extcalTime->_getUserTimeZone($user));;
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
475
                break;
476
477
            case _EXTCAL_EVENTS_MONTH:
478
            case _EXTCAL_EVENTS_CALENDAR_MONTH:
479
                $start = userTimeToServerTime(mktime(0, 0, 0, $month, 1, $year), $this->_extcalTime->_getUserTimeZone($user));
0 ignored issues
show
Bug introduced by
The method _getUserTimeZone() does not exist on XoopsModules\Extcal\Time. Did you maybe mean getUserTimeZone()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
480
                $end   = userTimeToServerTime(mktime(23, 59, 59, $month + 1, 1, $year) - _EXTCAL_TS_DAY, $this->_extcalTime->_getUserTimeZone($user));
0 ignored issues
show
Bug introduced by
The method _getUserTimeZone() does not exist on XoopsModules\Extcal\Time. Did you maybe mean getUserTimeZone()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
481
482
                $criteriaCompo->add(new \Criteria('event_start', $end, '<='));
483
                //$criteriaCompo->add( new \Criteria('event_end', $start, '>='));
0 ignored issues
show
Unused Code Comprehensibility introduced by
69% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
484
485
                break;
486
487 View Code Duplication
            case _EXTCAL_EVENTS_DAY:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
488
                $start = userTimeToServerTime(mktime(0, 0, 0, $month, $day, $year), $this->_extcalTime->_getUserTimeZone($user));
0 ignored issues
show
Bug introduced by
The method _getUserTimeZone() does not exist on XoopsModules\Extcal\Time. Did you maybe mean getUserTimeZone()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
489
                $end   = userTimeToServerTime(mktime(0, 0, 0, $month, $day + 1, $year), $this->_extcalTime->_getUserTimeZone($user));
0 ignored issues
show
Bug introduced by
The method _getUserTimeZone() does not exist on XoopsModules\Extcal\Time. Did you maybe mean getUserTimeZone()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
490
                //$criteriaCompo->add( new \Criteria('event_start', $end, '<='));
0 ignored issues
show
Unused Code Comprehensibility introduced by
69% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
491
492
                break;
493
494
            case _EXTCAL_EVENTS_YEAR:
495
                $start = userTimeToServerTime(mktime(0, 0, 0, 1, 1, $year), $this->_extcalTime->_getUserTimeZone($user));
0 ignored issues
show
Bug introduced by
The method _getUserTimeZone() does not exist on XoopsModules\Extcal\Time. Did you maybe mean getUserTimeZone()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
496
                $end   = userTimeToServerTime(mktime(0, 0, 0, 12, 31, $year), $this->_extcalTime->_getUserTimeZone($user));
0 ignored issues
show
Bug introduced by
The method _getUserTimeZone() does not exist on XoopsModules\Extcal\Time. Did you maybe mean getUserTimeZone()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
497
                break;
498
499
        }
500
        $formatDate = $extcalConfig['event_date_week'];
0 ignored issues
show
Unused Code introduced by
$formatDate is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
501
        //--------------------------------------------------------------------------
502
        $criteriaCompo->add(new \Criteria('event_isrecur', 1, '='));
503
        $criteriaCompo->setOrder($sens);
504
505
        $result = $this->getObjects($criteriaCompo);
506
        $events = $this->objectToArray($result, $externalKeys);
507
        $this->serverTimeToUserTimes($events);
508
509
        //Balyage de tous les evennements récurrents et creation de toutes le events
510
        $eventsR = [];
511
        //        while (list($k, $event) = each($events)) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
512
        foreach ($events as $k => $event) {
513
            //$te = $this->GetInterval($event, $start, $end);
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
514
            //$eventsR = array_merge($eventsR, $te);
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
515
            //echo 'event : ' . $event['event_id'] . '<br>';
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
516
            //Extcal\Utility::echoArray($event);
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
517
            $recurEvents = $this->getRecurEventToDisplay($event, $start, $end);
0 ignored issues
show
Bug introduced by
The variable $start does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $end does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
518
            if (count($recurEvents) > 0) {
519
                $eventsR = array_merge($eventsR, $recurEvents);
520
            }
521
522
            // Formating date
523
            //$eventsR = array_merge($eventsArray, $recurEvents);
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
524
        }
525
526
        return $eventsR;
527
    }
528
529
    /*****************************************************************
530
     *
531
     ****************************************************************
532
     * @param        $period
533
     * @param string $caption
534
     */
535
    public function echoDateArray($period, $caption = '')
536
    {
537
        if ('' != $caption) {
538
            echo "<hr>echoDateArray -> {$caption}<br>";
539
        } else {
540
            echo '<hr>echoDateArray<br>';
541
        }
542
543
        reset($period);
544
        foreach ($period as $dt) {
545
            echo $dt->format("l d-m-Y H:i:s\n") . '<br>';
546
        }
547
    }
548
549
    /*****************************************************************
550
     * Criteria
551
     ****************************************************************
552
     * @param     $day
553
     * @param     $month
554
     * @param     $year
555
     * @param int $cat
556
     * @return \CriteriaCompo
557
     */
558
    // Return the criteria compo object for a day
559
    public function getEventDayCriteria($day, $month, $year, $cat = 0)
0 ignored issues
show
Coding Style introduced by
getEventDayCriteria uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
560
    {
561
        $user = $GLOBALS['xoopsUser'];
562
563
        $dayStart      = userTimeToServerTime(mktime(0, 0, 0, $month, $day, $year), $this->_extcalTime->_getUserTimeZone($user));
0 ignored issues
show
Bug introduced by
The method _getUserTimeZone() does not exist on XoopsModules\Extcal\Time. Did you maybe mean getUserTimeZone()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
564
        $dayEnd        = userTimeToServerTime(mktime(23, 59, 59, $month, $day, $year), $this->_extcalTime->_getUserTimeZone($user));
0 ignored issues
show
Bug introduced by
The method _getUserTimeZone() does not exist on XoopsModules\Extcal\Time. Did you maybe mean getUserTimeZone()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
565
        $criteriaCompo = $this->getListCriteriaCompo($dayStart, $dayEnd, $cat, $user);
566
567
        return $criteriaCompo;
568
    }
569
570
    // Return the criteria compo object for a week
571
572
    /**
573
     * @param     $day
574
     * @param     $month
575
     * @param     $year
576
     * @param int $cat
577
     * @param int $nbDays
578
     *
579
     * @return \CriteriaCompo
580
     */
581
    public function getEventWeekCriteria($day, $month, $year, $cat = 0, $nbDays = 7)
0 ignored issues
show
Coding Style introduced by
getEventWeekCriteria uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
582
    {
583
        $user = $GLOBALS['xoopsUser'];
584
585
        $userStartTime = mktime(0, 0, 0, $month, $day, $year);
586
        $userEndTime   = $userStartTime + (_EXTCAL_TS_DAY * $nbDays);
587
        $weekStart     = userTimeToServerTime($userStartTime, $this->_extcalTime->_getUserTimeZone($user));
0 ignored issues
show
Bug introduced by
The method _getUserTimeZone() does not exist on XoopsModules\Extcal\Time. Did you maybe mean getUserTimeZone()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
588
        $weekEnd       = userTimeToServerTime($userEndTime, $this->_extcalTime->_getUserTimeZone($user));
0 ignored issues
show
Bug introduced by
The method _getUserTimeZone() does not exist on XoopsModules\Extcal\Time. Did you maybe mean getUserTimeZone()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
589
        $criteriaCompo = $this->_getCriteriaCompo($weekStart, $weekEnd, $cat, $user);
590
591
        return $criteriaCompo;
592
    }
593
594
    // Return the criteria compo object for a month
595
596
    /**
597
     * @param     $month
598
     * @param     $year
599
     * @param int $cat
600
     *
601
     * @return \CriteriaCompo
602
     */
603 View Code Duplication
    public function getEventMonthCriteria($month, $year, $cat = 0)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
getEventMonthCriteria uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
604
    {
605
        $user = $GLOBALS['xoopsUser'];
606
607
        $userStartTime = mktime(0, 0, 0, $month, 1, $year);
608
        $userEndTime   = mktime(23, 59, 59, $month + 1, 0, $year);
609
        $monthStart    = userTimeToServerTime($userStartTime, $this->_extcalTime->_getUserTimeZone($user));
0 ignored issues
show
Bug introduced by
The method _getUserTimeZone() does not exist on XoopsModules\Extcal\Time. Did you maybe mean getUserTimeZone()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
610
        $monthEnd      = userTimeToServerTime($userEndTime, $this->_extcalTime->_getUserTimeZone($user));
0 ignored issues
show
Bug introduced by
The method _getUserTimeZone() does not exist on XoopsModules\Extcal\Time. Did you maybe mean getUserTimeZone()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
611
        $criteriaCompo = $this->_getCriteriaCompo($monthStart, $monthEnd, $cat, $user);
612
613
        return $criteriaCompo;
614
    }
615
616
    // Return the criteria compo object for event occuring on a given year
617
618
    /**
619
     * @param     $year
620
     * @param int $cat
621
     *
622
     * @return CriteriaCompo
0 ignored issues
show
Documentation introduced by
Should the return type not be \CriteriaCompo?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
623
     */
624 View Code Duplication
    public function getEventYearCriteria($year, $cat = 0)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
getEventYearCriteria uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
625
    {
626
        $user = $GLOBALS['xoopsUser'];
627
628
        $userStartTime = mktime(0, 0, 0, 1, 1, $year);
629
        $userEndTime   = mktime(23, 59, 59, 12, 31, $year);
630
        $yearStart     = userTimeToServerTime($userStartTime, $this->_extcalTime->_getUserTimeZone($user));
0 ignored issues
show
Bug introduced by
The method _getUserTimeZone() does not exist on XoopsModules\Extcal\Time. Did you maybe mean getUserTimeZone()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
631
        $yearEnd       = userTimeToServerTime($userEndTime, $this->_extcalTime->_getUserTimeZone($user));
0 ignored issues
show
Bug introduced by
The method _getUserTimeZone() does not exist on XoopsModules\Extcal\Time. Did you maybe mean getUserTimeZone()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
632
        $criteriaCompo = $this->getListCriteriaCompo($yearStart, $yearEnd, $cat, $user);
633
634
        return $criteriaCompo;
635
    }
636
637
    /**********************************************************************
638
     * Debut de - A virer in fine
639
     **********************************************************************/
640
641
    /**********************************************************************
642
     * FIN de  - A virer in fine
643
     **********************************************************************/
644
645
    /**********************************************************************
646
     * Construction des criteres en fonction de la période
647
     *********************************************************************
648
     * @param $start
649
     * @param $end
650
     * @param $cat
651
     * @param $user
652
     * @return \CriteriaCompo
653
     */
654
655
    public function getCriteriaCompo($start, $end, $cat = 0, &$user)
656
    {
657
        $criteriaNoRecur = new \CriteriaCompo();
658
        $criteriaNoRecur->add(new \Criteria('event_start', $end, '<='));
659
        $criteriaNoRecur->add(new \Criteria('event_end', $start, '>='));
660
        $criteriaNoRecur->add(new \Criteria('event_isrecur', 0));
661
662
        $criteriaRecur = new \CriteriaCompo();
663
        $criteriaRecur->add(new \Criteria('event_recur_start', $end, '<='));
664
        $criteriaRecur->add(new \Criteria('event_recur_end', $start, '>='));
665
        $criteriaRecur->add(new \Criteria('event_isrecur', 1));
666
667
        $criteriaCompoDate = new \CriteriaCompo();
668
        $criteriaCompoDate->add($criteriaNoRecur, 'OR');
669
        $criteriaCompoDate->add($criteriaRecur, 'OR');
670
671
        $criteriaCompo = new \CriteriaCompo();
672
        $criteriaCompo->add($criteriaCompoDate);
673
674
        $criteriaCompo->add(new \Criteria('event_approved', 1));
675
        $this->addCatSelectCriteria($criteriaCompo, $cat);
676
        $this->addCatPermCriteria($criteriaCompo, $user);
677
        $criteriaCompo->setSort('event_start');
678
679
        return $criteriaCompo;
680
    }
681
682
    /**
683
     * @param     $start
684
     * @param     $end
685
     * @param int $cat
686
     * @param     $user
687
     *
688
     * @return \CriteriaCompo
689
     */
690 View Code Duplication
    public function getCalendarCriteriaCompo($start, $end, $cat = 0, &$user)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
691
    {
692
        global $extcalConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
693
        $criteriaCompo = $this->_getCriteriaCompo($start, $end, $cat, $user);
694
        //if (!$this->_extcalConfig['diplay_past_event_cal']) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
695
        if (!$extcalConfig['diplay_past_event_cal']) {
696
            $criteriaCompo->add(new \Criteria('event_end', time(), '>'));
697
        }
698
699
        return $criteriaCompo;
700
    }
701
702
    /**
703
     * @param     $start
704
     * @param     $end
705
     * @param int $cat
706
     * @param     $user
707
     *
708
     * @return \CriteriaCompo
709
     */
710 View Code Duplication
    public function getListCriteriaCompo($start, $end, $cat = 0, &$user)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
711
    {
712
        global $extcalConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
713
        $criteriaCompo = $this->_getCriteriaCompo($start, $end, $cat, $user);
714
        // if (!$this->_extcalConfig['diplay_past_event_list']) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
715
        if (!$extcalConfig['diplay_past_event_list']) {
716
            $criteriaCompo->add(new \Criteria('event_end', time(), '>'));
717
        }
718
719
        return $criteriaCompo;
720
    }
721
722
    // Return upcomming event
723
724
    /**
725
     * @param     $nbEvent
726
     * @param int $cat
727
     *
728
     * @return array
729
     */
730
    public function getUpcommingEvent($nbEvent, $cat = 0)
0 ignored issues
show
Coding Style introduced by
getUpcommingEvent uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
731
    {
732
        $now = time();
733
734
        $criteriaNoRecur = new \CriteriaCompo();
735
        $criteriaNoRecur->add(new \Criteria('event_start', $now, '>='));
736
        $criteriaNoRecur->add(new \Criteria('event_isrecur', 0));
737
738
        $criteriaRecur = new \CriteriaCompo();
739
        $criteriaRecur->add(new \Criteria('event_recur_start', $now, '>='));
740
        $criteriaRecur->add(new \Criteria('event_isrecur', 1));
741
742
        $criteriaCompoDate = new \CriteriaCompo();
743
        $criteriaCompoDate->add($criteriaNoRecur, 'OR');
744
        $criteriaCompoDate->add($criteriaRecur, 'OR');
745
746
        $criteriaCompo = new \CriteriaCompo();
747
        $criteriaCompo->add($criteriaCompoDate);
748
749
        $criteriaCompo->add(new \Criteria('event_approved', 1));
750
        $this->addCatSelectCriteria($criteriaCompo, $cat);
751
        $this->addCatPermCriteria($criteriaCompo, $GLOBALS['xoopsUser']);
752
753
        //mb ---------- TESTING ---------------------------
754
        //        $eventsU = $this->getEventsUniques($criteriaNoRecur);
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
755
        //        $eventsR = $this->getEventsRecurents($criteriaRecur);
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
756
        //        $events  = array_merge($eventsU, $eventsR);
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
757
758
        //var_dump($events);
759
760
        $criteriaCompo->setSort('event_start');
761
        $criteriaCompo->setLimit($nbEvent);
762
763
        //var_dump($this->getObjects($criteriaCompo));
0 ignored issues
show
Unused Code Comprehensibility introduced by
80% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
764
        //mb -------------------------------------
765
        return $this->getObjects($criteriaCompo);
766
    }
767
768
    // Return event occuring this day
769
770
    /**
771
     * @param     $nbEvent
772
     * @param int $cat
773
     *
774
     * @return array
775
     */
776
    public function getThisDayEvent($nbEvent, $cat = 0)
0 ignored issues
show
Coding Style introduced by
getThisDayEvent uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
777
    {
778
        $day   = date('j');
779
        $month = date('n');
780
        $year  = date('Y');
781
782
        $dayStart = mktime(0, 0, 0, $month, $day, $year);
783
        $dayEnd   = mktime(0, 0, 0, $month, $day + 1, $year);
784
785
        $criteriaCompo = new \CriteriaCompo();
786
        $this->addCatSelectCriteria($criteriaCompo, $cat);
787
        $this->addCatPermCriteria($criteriaCompo, $GLOBALS['xoopsUser']);
788
        $criteriaCompo->add(new \Criteria('event_end', $dayStart, '>='));
789
        $criteriaCompo->add(new \Criteria('event_start', $dayEnd, '<'));
790
        $criteriaCompo->add(new \Criteria('event_approved', 1));
791
        $criteriaCompo->setSort('event_start');
792
        $criteriaCompo->setLimit($nbEvent);
793
794
        return $this->getObjects($criteriaCompo);
795
    }
796
797
    // Return last added event
798
799
    /**
800
     * @param      $start
801
     * @param      $limit
802
     * @param int  $cat
803
     * @param bool $skipPerm
804
     *
805
     * @return array
806
     */
807
    public function getNewEvent($start, $limit, $cat = 0, $skipPerm = false)
0 ignored issues
show
Coding Style introduced by
getNewEvent uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
808
    {
809
        $criteriaCompo = new \CriteriaCompo();
810
        $this->addCatSelectCriteria($criteriaCompo, $cat);
811
        if (!$skipPerm) {
812
            $this->addCatPermCriteria($criteriaCompo, $GLOBALS['xoopsUser']);
813
        }
814
        $criteriaCompo->add(new \Criteria('event_approved', 1));
815
        $criteriaCompo->setSort('event_id');
816
        $criteriaCompo->setOrder('DESC');
817
        $criteriaCompo->setStart($start);
818
        $criteriaCompo->setLimit($limit);
819
820
        return $this->getObjects($criteriaCompo);
821
    }
822
823
    /**
824
     * @return int
0 ignored issues
show
Documentation introduced by
Should the return type not be integer|array?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
825
     */
826
    public function getCountNewEvent()
827
    {
828
        $criteriaCompo = new \CriteriaCompo();
829
        $this->addCatSelectCriteria($criteriaCompo, 0);
830
        $criteriaCompo->add(new \Criteria('event_approved', 1));
831
        $criteriaCompo->setSort('event_id');
832
833
        return $this->getCount($criteriaCompo);
834
    }
835
836
    // Return random upcomming event
837
838
    /**
839
     * @param     $nbEvent
840
     * @param int $cat
841
     *
842
     * @return array
843
     */
844
    public function getRandomEvent($nbEvent, $cat = 0)
0 ignored issues
show
Coding Style introduced by
getRandomEvent uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
845
    {
846
        $criteriaCompo = new \CriteriaCompo();
847
        $this->addCatSelectCriteria($criteriaCompo, $cat);
848
        $this->addCatPermCriteria($criteriaCompo, $GLOBALS['xoopsUser']);
849
        $criteriaCompo->add(new \Criteria('event_start', time(), '>='));
850
        $criteriaCompo->add(new \Criteria('event_approved', 1));
851
        $criteriaCompo->setSort('RAND()');
852
        $criteriaCompo->setLimit($nbEvent);
853
854
        return $this->getObjects($criteriaCompo);
855
    }
856
857
    /**
858
     * @return array
859
     */
860
    public function getPendingEvent()
861
    {
862
        $criteriaCompo = new \CriteriaCompo();
863
        $criteriaCompo->add(new \Criteria('event_approved', 0));
864
        $criteriaCompo->setSort('event_start');
865
866
        return $this->getObjects($criteriaCompo);
867
    }
868
869
    /**
870
     * @param \CriteriaElement $criteria
871
     * @param $user
872
     */
873 View Code Duplication
    public function addCatPermCriteria(\CriteriaElement $criteria, $user)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
874
    {
875
        $authorizedAccessCats = $this->_extcalPerm->getAuthorizedCat($user, 'extcal_cat_view');
876
        $count                = count($authorizedAccessCats);
877
        if ($count > 0) {
878
            $in = '(' . $authorizedAccessCats[0];
879
            array_shift($authorizedAccessCats);
880
            foreach ($authorizedAccessCats as $authorizedAccessCat) {
881
                $in .= ',' . $authorizedAccessCat;
882
            }
883
            $in .= ')';
884
            $criteria->add(new \Criteria('cat_id', $in, 'IN'));
885
        } else {
886
            $criteria->add(new \Criteria('cat_id', '(0)', 'IN'));
887
        }
888
    }
889
890
    /**
891
     * @param $criteria
892
     * @param $cats
893
     */
894
    public function addCatSelectCriteria(&$criteria, $cats = null)
895
    {
896
        if (!is_array($cats) && $cats > 0) {
897
            $criteria->add(new \Criteria('cat_id', $cats));
898
        }
899
        if (is_array($cats)) {
900
            if (false === array_search(0, $cats)) {
901
                $in = '(' . current($cats);
902
                array_shift($cats);
903
                foreach ($cats as $cat) {
904
                    $in .= ',' . $cat;
905
                }
906
                $in .= ')';
907
                $criteria->add(new \Criteria('cat_id', $in, 'IN'));
908
            }
909
        }
910
    }
911
912
    /**********************************************************************
913
     * formulaire d'edition des evennements*
914
     *********************************************************************
915
     * @param string $siteSide
916
     * @param string $mode
917
     * @param null   $data
918
     * @return \XoopsModules\Extcal\Form\ThemeForm
919
     */
920
    public function getEventForm($siteSide = 'user', $mode = 'new', $data = null)
0 ignored issues
show
Coding Style introduced by
getEventForm uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
getEventForm uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
921
    {
922
        global $xoopsModuleConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
923
        $catHandler  = Extcal\Helper::getInstance()->getHandler(_EXTCAL_CLN_CAT);
924
        $fileHandler = Extcal\Helper::getInstance()->getHandler(_EXTCAL_CLN_FILE);
925
926
        /***************************************************/
927
        //        require_once __DIR__ . '/etablissement.php';
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
928
        if ('admin' === $siteSide) {
929
            $action = 'event.php?op=enreg';
930
            $cats   = $catHandler->getAllCat($GLOBALS['xoopsUser'], 'all');
931
        } else {
932
            $action = 'post.php';
933
            $cats   = $catHandler->getAllCat($GLOBALS['xoopsUser']);
934
        }
935
        /***************************************************/
936
        $reccurOptions = [];
937
938
        if ('edit' === $mode || 'clone' === $mode) {
939
            if (!$event = $this->getEventWithNotApprove($data['event_id'])) {
940
                return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by XoopsModules\Extcal\EventHandler::getEventForm of type XoopsModules\Extcal\Form\ThemeForm.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
941
            }
942
            if ('clone' === $mode) {
943
                $data['event_id'] = 0;
944
                $event->setVar('event_id', 0);
0 ignored issues
show
Bug introduced by
The method setVar cannot be called on $event (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
945
                $newTitle = $event->getVar('event_title') . ' (' . _MD_EXTCAL_CLONE_OF . $data['event_id'] . ')';
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $event (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
946
                $event->setVar('event_title', $newTitle);
0 ignored issues
show
Bug introduced by
The method setVar cannot be called on $event (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
947
            }
948
949
            $formTitle           = _MD_EXTCAL_EDIT_EVENT;
950
            $formName            = 'modify_event';
0 ignored issues
show
Unused Code introduced by
$formName is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
951
            $title               = $event->getVar('event_title', 'e');
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $event (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
952
            $cat                 = $event->getVar('cat_id');
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $event (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
953
            $desc                = $event->getVar('event_desc', 'e');
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $event (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
954
            $nbMember            = $event->getVar('event_nbmember', 'e');
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $event (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
955
            $organisateur        = $event->getVar('event_organisateur');
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $event (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
956
            $contact             = $event->getVar('event_contact', 'e');
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $event (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
957
            $url                 = $event->getVar('event_url', 'e');
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $event (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
958
            $email               = $event->getVar('event_email', 'e');
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $event (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
959
            $event_address       = $event->getVar('event_address', 'e');
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $event (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
960
            $startDateValue      = xoops_getUserTimestamp($event->getVar('event_start'), $this->_extcalTime->_getUserTimeZone($GLOBALS['xoopsUser']));
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $event (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
Bug introduced by
The method _getUserTimeZone() does not exist on XoopsModules\Extcal\Time. Did you maybe mean getUserTimeZone()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
961
            $endDateValue        = xoops_getUserTimestamp($event->getVar('event_end'), $this->_extcalTime->_getUserTimeZone($GLOBALS['xoopsUser']));
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $event (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
Bug introduced by
The method _getUserTimeZone() does not exist on XoopsModules\Extcal\Time. Did you maybe mean getUserTimeZone()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
962
            $event_picture1      = $event->getVar('event_picture1');
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $event (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
963
            $event_picture2      = $event->getVar('event_picture2');
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $event (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
964
            $event_price         = $event->getVar('event_price');
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $event (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
965
            $event_etablissement = $event->getVar('event_etablissement');
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $event (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
966
            $event_icone         = $event->getVar('event_icone');
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $event (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
967
968
            // Configuring recurring form
969
            $eventOptions = explode('|', $event->getVar('event_recur_rules'));
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $event (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
970
            $reccurMode   = $eventOptions[0];
971
            array_shift($eventOptions);
972 View Code Duplication
            switch ($reccurMode) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
973
974
                case 'daily':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
975
976
                    $reccurOptions['rrule_freq']           = 'daily';
977
                    $reccurOptions['rrule_daily_interval'] = $eventOptions[0];
978
979
                    break;
980
981
                case 'weekly':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
982
983
                    $reccurOptions['rrule_freq']            = 'weekly';
984
                    $reccurOptions['rrule_weekly_interval'] = $eventOptions[0];
985
                    array_shift($eventOptions);
986
                    $reccurOptions['rrule_weekly_bydays'] = $eventOptions;
987
988
                    break;
989
990
                case 'monthly':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
991
992
                    $reccurOptions['rrule_freq']             = 'monthly';
993
                    $reccurOptions['rrule_monthly_interval'] = $eventOptions[0];
994
                    array_shift($eventOptions);
995
                    if (0 !== strpos($eventOptions[0], 'MD')) {
996
                        $reccurOptions['rrule_monthly_byday'] = $eventOptions[0];
997
                    } else {
998
                        $reccurOptions['rrule_bymonthday'] = substr($eventOptions[0], 2);
999
                    }
1000
1001
                    break;
1002
1003
                case 'yearly':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1004
1005
                    $reccurOptions['rrule_freq']            = 'yearly';
1006
                    $reccurOptions['rrule_yearly_interval'] = $eventOptions[0];
1007
                    array_shift($eventOptions);
1008
                    $reccurOptions['rrule_yearly_byday'] = $eventOptions[0];
1009
                    array_shift($eventOptions);
1010
                    $reccurOptions['rrule_yearly_bymonths'] = $eventOptions;
1011
1012
                    break;
1013
1014
            }
1015
1016
            $files = $fileHandler->objectToArray($fileHandler->getEventFiles($data['event_id']));
1017
            $fileHandler->formatFilesSize($files);
1018
        } elseif ('preview' === $mode) {
1019
            $formTitle           = _MD_EXTCAL_SUBMIT_EVENT;
1020
            $formName            = 'submit_event';
0 ignored issues
show
Unused Code introduced by
$formName is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1021
            $title               = $data['event_title'];
1022
            $cat                 = $data['cat_id'];
1023
            $desc                = $data['event_desc'];
1024
            $nbMember            = $data['event_nbmember'];
1025
            $organisateur        = $data['event_organisateur'];
1026
            $contact             = $data['event_contact'];
1027
            $url                 = $data['event_url'];
1028
            $email               = $data['event_email'];
1029
            $event_address       = $data['event_address'];
1030
            $startDateValue      = $data['event_start'];
1031
            $endDateValue        = $data['event_end'];
1032
            $eventEndOk          = $data['have_end'];
0 ignored issues
show
Unused Code introduced by
$eventEndOk is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1033
            $event_picture1      = $data['event_picture1'];
1034
            $event_picture2      = $data['event_picture2'];
1035
            $event_price         = $data['event_price'];
1036
            $event_etablissement = $data['event_etablissement'];
1037
            $event_icone         = $data['event_icone'];
1038
1039
            // Configuring recurring form
1040
            $eventOptions = explode('|', $this->getRecurRules($_POST));
1041
            $reccurMode   = $eventOptions[0];
1042
            array_shift($eventOptions);
1043 View Code Duplication
            switch ($reccurMode) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1044
1045
                case 'daily':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1046
1047
                    $reccurOptions['rrule_freq']           = 'daily';
1048
                    $reccurOptions['rrule_daily_interval'] = $eventOptions[0];
1049
1050
                    break;
1051
1052
                case 'weekly':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1053
1054
                    $reccurOptions['rrule_freq']            = 'weekly';
1055
                    $reccurOptions['rrule_weekly_interval'] = $eventOptions[0];
1056
                    array_shift($eventOptions);
1057
                    $reccurOptions['rrule_weekly_bydays'] = $eventOptions;
1058
1059
                    break;
1060
1061
                case 'monthly':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1062
1063
                    $reccurOptions['rrule_freq']             = 'monthly';
1064
                    $reccurOptions['rrule_monthly_interval'] = $eventOptions[0];
1065
                    array_shift($eventOptions);
1066
                    if (0 !== strpos($eventOptions[0], 'MD')) {
1067
                        $reccurOptions['rrule_monthly_byday'] = $eventOptions[0];
1068
                    } else {
1069
                        $reccurOptions['rrule_bymonthday'] = substr($eventOptions[0], 2);
1070
                    }
1071
1072
                    break;
1073
1074
                case 'yearly':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1075
1076
                    $reccurOptions['rrule_freq']            = 'yearly';
1077
                    $reccurOptions['rrule_yearly_interval'] = $eventOptions[0];
1078
                    array_shift($eventOptions);
1079
                    $reccurOptions['rrule_yearly_byday'] = $eventOptions[0];
1080
                    array_shift($eventOptions);
1081
                    $reccurOptions['rrule_yearly_bymonths'] = $eventOptions;
1082
1083
                    break;
1084
1085
            }
1086
1087
            $files = $fileHandler->objectToArray($fileHandler->getEventFiles($data['event_id']));
1088
            $fileHandler->formatFilesSize($files);
1089
        } else {
1090
            $formTitle           = _MD_EXTCAL_SUBMIT_EVENT;
1091
            $formName            = 'submit_event';
0 ignored issues
show
Unused Code introduced by
$formName is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1092
            $title               = '';
1093
            $cat                 = '';
1094
            $desc                = '';
1095
            $nbMember            = 0;
1096
            $organisateur        = '';
1097
            $contact             = '';
1098
            $url                 = '';
1099
            $email               = '';
1100
            $event_address       = '';
1101
            $startDateValue      = 0;
1102
            $endDateValue        = 0;
1103
            $eventEndOk          = 0;
0 ignored issues
show
Unused Code introduced by
$eventEndOk is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1104
            $event_picture1      = '';
1105
            $event_picture2      = '';
1106
            $event_price         = '';
1107
            $event_etablissement = '';
1108
            $files               = [];
1109
            $event_icone         = '';
1110
        }
1111
1112
        // Create XoopsForm Object
1113
        $form = new Extcal\Form\ThemeForm($formTitle, 'event_form', $action, 'post', true);
1114
        // Add this extra to allow file upload
1115
        $form->setExtra('enctype="multipart/form-data"');
1116
1117
        //-----------------------------------------------
1118
        // Title
1119
        $form->addElement(new \XoopsFormText(_MD_EXTCAL_TITLE, 'event_title', 80, 255, $title), true);
1120
        //-----------------------------------------------
1121
        // Category select
1122
        $catSelect = new \XoopsFormSelect(_MD_EXTCAL_CATEGORY, 'cat_id', $cat);
1123
        foreach ($cats as $cat) {
1124
            $catSelect->addOption($cat->getVar('cat_id'), $cat->getVar('cat_name'));
1125
        }
1126
        $form->addElement($catSelect, true);
1127
        //-----------------------------------------------------------
1128
1129
        $file_path = __DIR__ . '/../assets/css/images';
1130
        $tf        = \XoopsLists::getImgListAsArray($file_path);
1131
        array_unshift($tf, _MD_EXTCAL_NONE);
1132
        $xfIcones = new \XoopsFormSelect(_MD_EXTCAL_ICONE, 'event_icone', $event_icone, '');
1133
        $xfIcones->addOptionArray($tf);
1134
        $form->addElement($xfIcones, false);
1135
        //-----------------------------------------------------------
1136
        //etablissement
1137
        $etablissementHandler = Extcal\Helper::getInstance()->getHandler(_EXTCAL_CLN_ETABLISSEMENT);
1138
        $etablissement_select = new \XoopsFormSelect(_MD_EXTCAL_ETABLISSEMENT, 'event_etablissement', $event_etablissement);
1139
        $criteria             = new \CriteriaCompo();
1140
        $criteria->setSort('nom');
1141
        $criteria->setOrder('ASC');
1142
1143
        //$lstEtablissement = $etablissementHandler->getList($criteria);
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1144
        $etablissement_arr = $etablissementHandler->getAll($criteria);
1145
        $tEts              = [];
1146
        $tEts[0]           = _MD_EXTCAL_NONE;
1147
        foreach (array_keys($etablissement_arr) as $i) {
1148
            $tEts[$etablissement_arr[$i]->getVar('id')] = $etablissement_arr[$i]->getVar('nom');
1149
            //            $tEts[$etablissement_arr[$i]['id']] = $etablissement_arr[$i]['nom'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
82% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1150
        }
1151
        //array_unshift($tEts, _MD_EXTCAL_NONE);
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1152
1153
        $etablissement_select->addOptionArray($tEts);
1154
        $form->addElement($etablissement_select, true);
1155
1156
        //-----------------------------------------------------------
1157
1158
        // Start and end
1159
        new Extcal\Form\FormDateTime($form, $startDateValue, $endDateValue); //mb
1160
1161
        global $xoopsUser, $xoopsModule;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
1162
        $isAdmin = false;
1163
        if (is_object($xoopsUser)) {
1164
            $isAdmin = $xoopsUser->isAdmin($xoopsModule->getVar('mid'));
1165
        }
1166
1167
        // Description
1168 View Code Duplication
        if (class_exists('XoopsFormEditor')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1169
            $options['name']   = 'event_desc';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$options was never initialized. Although not strictly required by PHP, it is generally a good practice to add $options = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1170
            $options['value']  = $desc;
1171
            $options['rows']   = 5;
1172
            $options['cols']   = '100%';
1173
            $options['width']  = '100%';
1174
            $options['height'] = '200px';
1175
            if ($isAdmin) {
1176
                $descEditor = new \XoopsFormEditor(_MD_EXTCAL_DESCRIPTION, $xoopsModuleConfig['editorAdmin'], $options, $nohtml = false, $onfailure = 'textarea');
1177
            } else {
1178
                $descEditor = new \XoopsFormEditor(_MD_EXTCAL_DESCRIPTION, $xoopsModuleConfig['editorUser'], $options, $nohtml = false, $onfailure = 'textarea');
1179
            }
1180
        } else {
1181
            $descEditor = new \XoopsFormDhtmlTextArea(_MD_EXTCAL_DESCRIPTION, 'event_desc', $desc, '100%', '100%');
1182
        }
1183
        $form->addElement($descEditor);
1184
1185
        // Max registered member for this event
1186
        $nbMemberElement = new \XoopsFormText(_MD_EXTCAL_NBMEMBER, 'event_nbmember', 4, 4, $nbMember);
1187
        $nbMemberElement->setDescription(_MD_EXTCAL_NBMEMBER_DESC);
1188
        $form->addElement($nbMemberElement, false);
1189
1190
        //Price and monnaie
1191
        $monnaie_price = new \XoopsFormElementTray(_MD_EXTCAL_PRICE, '');
1192
        //price
1193
        $monnaie_price->addElement(new \XoopsFormText('', 'event_price', 20, 255, $event_price));
1194
        //monnaie
1195
        $monnaie = new \XoopsFormLabel(_MD_EXTCAL_DEVISE2, '');
1196
        $monnaie_price->addElement($monnaie);
1197
        $form->addElement($monnaie_price);
1198
        //----------------------------------------------------------------
1199
        $form->addElement(new \XoopsFormText(_MD_EXTCAL_ORGANISATEUR, 'event_organisateur', 80, 255, $organisateur), false);
1200
        // Contact
1201
        $form->addElement(new \XoopsFormText(_MD_EXTCAL_CONTACT, 'event_contact', 80, 255, $contact), false);
1202
        // Url
1203
        $form->addElement(new \XoopsFormText(_MD_EXTCAL_URL, 'event_url', 80, 255, $url), false);
1204
        // Email
1205
        $form->addElement(new \XoopsFormText(_MD_EXTCAL_EMAIL, 'event_email', 80, 255, $email), false);
1206
1207
        // Address
1208 View Code Duplication
        if (class_exists('XoopsFormEditor')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1209
            $options['name']   = 'event_address';
0 ignored issues
show
Bug introduced by
The variable $options does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1210
            $options['value']  = $event_address;
1211
            $options['rows']   = 5;
1212
            $options['cols']   = '100%';
1213
            $options['width']  = '100%';
1214
            $options['height'] = '200px';
1215
            if ($isAdmin) {
1216
                $addressEditor = new \XoopsFormEditor(_MD_EXTCAL_DESCRIPTION, $xoopsModuleConfig['editorAdmin'], $options, $nohtml = false, $onfailure = 'textarea');
1217
            } else {
1218
                $addressEditor = new \XoopsFormEditor(_MD_EXTCAL_DESCRIPTION, $xoopsModuleConfig['editorUser'], $options, $nohtml = false, $onfailure = 'textarea');
1219
            }
1220
        } else {
1221
            $addressEditor = new \XoopsFormDhtmlTextArea(_MD_EXTCAL_DESCRIPTION, 'event_address', $event_address, '100%', '100%');
1222
        }
1223
        $form->addElement($addressEditor);
1224
1225
        // Recurence form
1226
        $form->addElement(new Extcal\Form\FormRecurRules($reccurOptions));
1227
        // File attachement
1228
        $fileElmtTray = new \XoopsFormElementTray(_MD_EXTCAL_FILE_ATTACHEMENT, '<br>');
1229
1230
        // If they are attached file to this event
1231
        if (count($files) > 0) {
1232
            $eventFiles = new Extcal\Form\FormFileCheckBox('', 'filetokeep');
1233
            foreach ($files as $file) {
1234
                $name = $file['file_nicename'] . ' (<i>' . $file['file_mimetype'] . '</i>) ' . $file['formated_file_size'];
1235
                $eventFiles->addOption($file['file_id'], $name);
1236
            }
1237
            $fileElmtTray->addElement($eventFiles);
1238
        }
1239
        $fileElmtTray->addElement(new \XoopsFormFile(_MD_EXTCAL_FILE_ATTACHEMENT, 'event_file', 3145728));
1240
        $form->addElement($fileElmtTray);
1241
1242
        if (isset($data['event_id'])) {
1243
            $form->addElement(new \XoopsFormHidden('event_id', $data['event_id']), false);
1244
        }
1245
        //Hack Kraven0
1246
        ///////////////////////////////////////////////////////////////////////////////
1247
        //Picture1
1248
        $file_tray = new \XoopsFormElementTray(sprintf(_MD_EXTCAL_FORM_IMG, 1), '');
1249 View Code Duplication
        if (!empty($event_picture1)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1250
            $file_tray->addElement(new \XoopsFormLabel('', "<img src='" . XOOPS_URL . '/uploads/extcal/' . $event_picture1 . "' name='image' id='image' alt=''><br><br>"));
1251
            $check_del_img = new \XoopsFormCheckBox('', 'delimg_1');
1252
            $check_del_img->addOption(1, _MD_EXTCAL_DEL_IMG);
1253
            $file_tray->addElement($check_del_img);
1254
            $file_img = new \XoopsFormFile(_MD_EXTCAL_IMG, 'attachedimage1', 2145728);
1255
            unset($check_del_img);
1256
        } else {
1257
            $file_img = new \XoopsFormFile('', 'attachedimage1', 2145728);
1258
        }
1259
        $file_img->setExtra("size ='40'");
1260
        $file_tray->addElement($file_img);
1261
        $msg        = sprintf(_MD_EXTCAL_IMG_CONFIG, (int)(400728 / 1000), 500, 500);
1262
        $file_label = new \XoopsFormLabel('', '<br>' . $msg);
1263
        $file_tray->addElement($file_label);
1264
        $form->addElement($file_tray);
1265
        $form->addElement(new \XoopsFormHidden('file1', $event_picture1));
1266
        unset($file_img, $file_tray);
1267
        //Picture2
1268
        $file_tray = new \XoopsFormElementTray(sprintf(_MD_EXTCAL_FORM_IMG, 2), '');
1269 View Code Duplication
        if (!empty($event_picture2)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1270
            $file_tray->addElement(new \XoopsFormLabel('', "<img src='" . XOOPS_URL . '/uploads/extcal/' . $event_picture2 . "' name='image' id='image' alt=''><br><br>"));
1271
            $check_del_img = new \XoopsFormCheckBox('', 'delimg_2');
1272
            $check_del_img->addOption(1, _MD_EXTCAL_DEL_IMG);
1273
            $file_tray->addElement($check_del_img);
1274
            $file_img = new \XoopsFormFile(_MD_EXTCAL_IMG, 'attachedimage2', 2145728);
1275
            unset($check_del_img);
1276
        } else {
1277
            $file_img = new \XoopsFormFile('', 'attachedimage2', 2145728);
1278
        }
1279
        $file_img->setExtra("size ='40'");
1280
        $file_tray->addElement($file_img);
1281
        $msg        = sprintf(_MD_EXTCAL_IMG_CONFIG, (int)(400728 / 1000), 500, 500);
1282
        $file_label = new \XoopsFormLabel('', '<br>' . $msg);
1283
        $file_tray->addElement($file_label);
1284
        $form->addElement($file_tray);
1285
        $form->addElement(new \XoopsFormHidden('file2', $event_picture2));
1286
        unset($file_img, $file_tray);
1287
        ///////////////////////////////////////////////////////////////////////////////
1288
1289
        $buttonElmtTray = new \XoopsFormElementTray('', '&nbsp;');
1290
        $buttonElmtTray->addElement(new \XoopsFormButton('', 'form_submit', _SUBMIT, 'submit'), false);
1291
        if ('user' === $siteSide) {
1292
            $buttonElmtTray->addElement(new \XoopsFormButton('', 'form_preview', _MD_EXTCAL_PREVIEW, 'submit'), false);
1293
        }
1294
        $form->addElement($buttonElmtTray);
1295
1296
        return $form;
1297
    }
1298
1299
    /********************************************************************/
1300
1301
    /**
1302
     * @param $parm
1303
     *
1304
     * @return bool
1305
     */
1306
    public function getIsRecur($parm)
1307
    {
1308
        $recurFreq = ['daily', 'weekly', 'monthly', 'yearly'];
1309
1310
        return in_array($parm['rrule_freq'], $recurFreq);
1311
    }
1312
1313
    /**
1314
     * @param $parm
1315
     *
1316
     * @return string
1317
     */
1318
    public function getRecurRules($parm)
1319
    {
1320
        //Extcal\Utility::echoArray($parm);exit;
0 ignored issues
show
Unused Code Comprehensibility introduced by
78% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1321
1322
        // If this isn't a reccuring event
1323
        if (!$this->getIsRecur($parm)) {
1324
            return '';
1325
        }
1326
1327
        $recurRules = '';
1328
1329
        $recurFreq = $parm['rrule_freq'];
1330
1331
        switch ($recurFreq) {
1332
1333
            case 'daily':
1334
                if (!isset($parm['rrule_daily_interval'])) {
1335
                    $parm['rrule_daily_interval'] = 0;
1336
                }
1337
                $recurRules = 'daily|';
1338
                $recurRules .= $parm['rrule_daily_interval'];
1339
1340
                break;
1341
1342
            case 'weekly':
1343
                if (!isset($parm['rrule_weekly_interval'])) {
1344
                    $parm['rrule_weekly_interval'] = 0;
1345
                }
1346
                $recurRules = 'weekly|';
1347
                $recurRules .= $parm['rrule_weekly_interval'];
1348
                foreach ($parm['rrule_weekly_bydays'] as $day) {
1349
                    $recurRules .= '|' . $day;
1350
                }
1351
1352
                break;
1353
1354
            case 'monthly':
1355
                if (!isset($parm['rrule_monthly_interval'])) {
1356
                    $parm['rrule_monthly_interval'] = 0;
1357
                }
1358
                $recurRules = 'monthly|';
1359
                $recurRules .= $parm['rrule_monthly_interval'] . '|';
1360
                if ('' != $parm['rrule_monthly_byday']) {
1361
                    $recurRules .= $parm['rrule_monthly_byday'];
1362
                } else {
1363
                    $recurRules .= 'MD' . $parm['rrule_bymonthday'];
1364
                }
1365
1366
                break;
1367
1368
            case 'yearly':
1369
                //JJD - to valid modif
1370
                //
1371
                //                 if ($parm['rrule_yearly_byday'] == "") {
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1372
                //                     list($year, $month, $day) = explode("-", $parm['event_start']['date']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1373
                //                     $parm['rrule_yearly_byday'] = date("j", mktime(0, 0, 0, $month, $day, $year));
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1374
                //                 }
1375
                //
1376
                //                 $recurRules = 'yearly|';
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1377
                //                 $recurRules .= $parm['rrule_yearly_interval'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1378
                //                 $recurRules .= '|' . $parm['rrule_yearly_byday'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1379
                //                 foreach (
1380
                //                     $parm['rrule_yearly_bymonths'] as $month
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1381
                //) {
1382
                //                     $recurRules .= '|' . $month;
1383
                //                 }
1384
                //
1385
                //                 break;
1386
1387
                if (!isset($parm['rrule_yearly_interval'])) {
1388
                    $parm['rrule_yearly_interval'] = 0;
1389
                }
1390
                if ('' == $parm['rrule_yearly_byday']) {
1391
                    $time                       = strtotime($parm['event_start']['date']);
1392
                    $parm['rrule_yearly_byday'] = date('j', mktime(0, 0, 0, date('m', $time), date('d', $time), date('Y', $time)));
1393
                }
1394
1395
                $recurRules = 'yearly|';
1396
                $recurRules .= $parm['rrule_yearly_interval'];
1397
                $recurRules .= '|' . $parm['rrule_yearly_byday'];
1398
                foreach ($parm['rrule_yearly_bymonths'] as $month) {
1399
                    $recurRules .= '|' . $month;
1400
                }
1401
1402
                break;
1403
1404
        }
1405
1406
        return $recurRules;
1407
    }
1408
1409
    /**
1410
     * @param $data
1411
     * @param $parm
1412
     *
1413
     * @return int
1414
     */
1415
    public function getRecurStart($data, $parm)
1416
    {
1417
1418
        // If this isn't a reccuring event
1419
        if (!$this->getIsRecur($parm)) {
1420
            return 0;
1421
        }
1422
1423
        return $data['event_start'];
1424
    }
1425
1426
    /**
1427
     * @param $data
1428
     * @param $parm
1429
     *
1430
     * @return int
0 ignored issues
show
Documentation introduced by
Should the return type not be integer|double?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
1431
     */
1432
    public function getRecurEnd($data, $parm)
1433
    {
1434
        if (!$this->getIsRecur($parm)) {
1435
            return 0;
1436
        }
1437
1438
        $recurFreq = $parm['rrule_freq'];
1439
1440
        $recurStart = $this->getRecurStart($data, $parm);
1441
1442
        switch ($recurFreq) {
1443
1444
            case 'daily':
1445
                $interval = $parm['rrule_daily_interval'];
1446
                $recurEnd = $recurStart + ($interval * _EXTCAL_TS_DAY) - 1;
1447
1448
                break;
1449
1450
            case 'weekly':
1451
                global $extcalConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
1452
1453
                // Getting the first weekday TS
1454
                $startWeekTS = mktime(0, 0, 0, date('n', $data['event_recur_start']), date('j', $data['event_recur_start']), date('Y', $data['event_recur_start']));
1455
                $offset      = date('w', $startWeekTS) - $extcalConfig['week_start_day'];
1456
                $startWeekTS -= ($offset * _EXTCAL_TS_DAY);
1457
1458
                $recurEnd = $startWeekTS + ($parm['rrule_weekly_interval'] * _EXTCAL_TS_WEEK) - 1;
1459
1460
                break;
1461
1462
            case 'monthly':
1463
                $recurEnd = $recurStart + ($parm['rrule_monthly_interval'] * 2678400) - 1;
1464
1465
                break;
1466
1467
            case 'yearly':
1468
                $recurEnd = $recurStart + ($parm['rrule_yearly_interval'] * 32140800) - 1;
1469
1470
                break;
1471
1472
        }
1473
1474
        return $recurEnd;
0 ignored issues
show
Bug introduced by
The variable $recurEnd does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1475
    }
1476
1477
    /*******************************************************************
1478
     *
1479
     ******************************************************************
1480
     * @param $event
1481
     * @param $periodStart
1482
     * @param $periodEnd
1483
     * @return array
1484
     */
1485
    public function getRecurEventToDisplay($event, $periodStart, $periodEnd)
1486
    {
1487
        global $extcalConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
1488
1489
        $recuEvents   = [];
1490
        $eventOptions = explode('|', $event['event_recur_rules']);
1491
1492
        switch ($eventOptions[0]) {
1493
1494
            case 'daily':
1495
                array_shift($eventOptions);
1496
                $rRuleInterval = $eventOptions[0];
1497
                if ('' == $rRuleInterval || 0 == $rRuleInterval) {
1498
                    $rRuleInterval = 54;
1499
                }
1500
1501
                $occurEventStart = $event['event_recur_start'];
1502
                $occurEventEnd   = $event['event_recur_start'] + ($event['event_end'] - $event['event_start']);
1503
1504
                $nbOccur = 0;
1505
                // This variable is used to stop the loop after we add all occur on the view to keep good performance
1506
                $isOccurOnPeriod = false;
1507
                // Parse all occurence of this event
1508
                while ($nbOccur < $rRuleInterval) {
1509
                    // Add this event occurence only if it's on the period view
1510
                    if // Event start falls within search period
1511
                    ($occurEventStart <= $periodEnd
1512
                     && // Event end falls within search period
1513
                     $occurEventEnd >= $periodStart) {
1514
                        $event['event_start'] = $occurEventStart;
1515
                        $event['event_end']   = $occurEventEnd;
1516
1517
                        $recuEvents[]    = $event;
1518
                        $isOccurOnPeriod = true;
1519
                    } elseif ($isOccurOnPeriod) {
1520
                        break;
1521
                    }
1522
1523
                    $occurEventStart += _EXTCAL_TS_DAY;
1524
                    $occurEventEnd   += _EXTCAL_TS_DAY;
1525
1526
                    ++$nbOccur;
1527
                }
1528
1529
                break;
1530
1531
            case 'weekly':
1532
                global $extcalConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
1533
1534
                array_shift($eventOptions);
1535
                $rRuleInterval = $eventOptions[0];
1536
                if ('' == $rRuleInterval || 0 == $rRuleInterval) {
1537
                    $rRuleInterval = 54;
1538
                }
1539
                array_shift($eventOptions);
1540
1541
                // Getting the first weekday TS
1542
                $startWeekTS = mktime(0, 0, 0, date('n', $event['event_recur_start']), date('j', $event['event_recur_start']), date('Y', $event['event_recur_start']));
1543
                $offset      = date('w', $startWeekTS) - $extcalConfig['week_start_day'];
1544
                $startWeekTS = $startWeekTS - ($offset * _EXTCAL_TS_DAY) + _EXTCAL_TS_WEEK;
1545
1546
                $occurEventStart = $event['event_recur_start'];
1547
                $occurEventEnd   = $event['event_recur_start'] + ($event['event_end'] - $event['event_start']);
1548
1549
                $dayArray = ['SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'];
1550
1551
                $nbOccur = 0;
1552
1553
                // Parse all occurence of this event
1554
                while ($nbOccur < $rRuleInterval) {
1555
                    // Add this event occurence only if it's on the period view and according to day
1556
                    if ($occurEventStart <= $periodEnd // Event start falls within search period
1557
                        && $occurEventEnd >= $periodStart // Event end falls within search period
1558
                        && in_array($dayArray[date('w', $occurEventStart)], $eventOptions)) {
1559
                        // This week day is selected
1560
1561
                        $event['event_start'] = $occurEventStart;
1562
                        $event['event_end']   = $occurEventEnd;
1563
1564
                        $recuEvents[] = $event;
1565
                    }
1566
1567
                    $occurEventStart += _EXTCAL_TS_DAY;
1568
                    $occurEventEnd   += _EXTCAL_TS_DAY;
1569
1570
                    if ($occurEventStart >= $startWeekTS) {
1571
                        ++$nbOccur;
1572
                        $startWeekTS += _EXTCAL_TS_WEEK;
1573
                    }
1574
                }
1575
1576
                break;
1577
1578
            case 'monthly':
1579
                array_shift($eventOptions);
1580
                $rRuleInterval = $eventOptions[0];
1581
                if ('' == $rRuleInterval || 0 == $rRuleInterval) {
1582
                    $rRuleInterval = 100;
1583
                }
1584
                array_shift($eventOptions);
1585
1586
                $day   = date('j', $event['event_recur_start']);
1587
                $month = date('n', $event['event_recur_start']);
1588
                $year  = date('Y', $event['event_recur_start']);
1589
1590
                $nbOccur = 0;
1591
1592
                $eventHourOccurStart = $event['event_recur_start'] - mktime(0, 0, 0, $month, $day, $year);
1593
                $eventHourOccurEnd   = $event['event_end'] - $event['event_start'];
1594
1595
                // Parse all occurence of this event
1596
                while ($nbOccur < $rRuleInterval) {
1597
                    $eventDayOccurStart = $this->_getOccurTS($month, $year, $eventOptions[0]);
1598
                    if (!$eventDayOccurStart) {
1599
                        $eventDayOccurStart = mktime(0, 0, 0, $month, $day, $year);
1600
                    }
1601
1602
                    $occurEventStart = $eventDayOccurStart + $eventHourOccurStart;
1603
                    $occurEventEnd   = $occurEventStart + $eventHourOccurEnd;
1604
1605 View Code Duplication
                    if // Event start falls within search period
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1606
                    ($occurEventStart <= $periodEnd
1607
                     && // Event end falls within search period
1608
                     $occurEventEnd >= $periodStart
1609
                     && // This occur is after start reccur date
1610
                     $occurEventStart >= $event['event_recur_start']) {
1611
                        $event['event_start'] = $occurEventStart;
1612
                        $event['event_end']   = $occurEventEnd;
1613
1614
                        $recuEvents[] = $event;
1615
                    } elseif ($occurEventStart > $periodEnd) {
1616
                        break;
1617
                    }
1618
1619
                    if (13 == ++$month) {
1620
                        $month = 1;
1621
                        ++$year;
1622
                    }
1623
1624
                    ++$nbOccur;
1625
                }
1626
1627
                break;
1628
1629
            case 'yearly':
1630
                array_shift($eventOptions);
1631
                $rRuleInterval = $eventOptions[0];
1632
                if ('' == $rRuleInterval || 0 == $rRuleInterval) {
1633
                    $rRuleInterval = 10;
1634
                }
1635
                array_shift($eventOptions);
1636
                $dayCode = $eventOptions[0];
1637
                array_shift($eventOptions);
1638
1639
                $day   = date('j', $event['event_recur_start']);
1640
                $month = date('n', $event['event_recur_start']);
1641
                $year  = date('Y', $event['event_recur_start']);
1642
1643
                $nbOccur = 0;
1644
1645
                $eventHourOccurStart = $event['event_recur_start'] - mktime(0, 0, 0, $month, $day, $year);
1646
                $eventHourOccurEnd   = $event['event_end'] - $event['event_start'];
1647
1648
                // If recurring month not specified, make it starting month
1649
                if (!count($eventOptions)) {
1650
                    $eventOptions[] = $month;
1651
                }
1652
1653
                // Parse all occurence of this event
1654
                while ($nbOccur < $rRuleInterval) {
1655
                    $eventDayOccurStart = $this->_getOccurTS($month, $year, $dayCode);
1656
                    if (!$eventDayOccurStart) {
1657
                        $eventDayOccurStart = mktime(0, 0, 0, $month, $day, $year);
1658
                    }
1659
1660
                    $occurEventStart = $eventDayOccurStart + $eventHourOccurStart;
1661
                    $occurEventEnd   = $eventDayOccurStart + $eventHourOccurEnd;
1662
1663 View Code Duplication
                    if // Event start falls within search period
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1664
                    (($occurEventStart <= $periodEnd)
1665
                     && // Event end falls within search period
1666
                     ($occurEventEnd >= $periodStart)
1667
                     && // This week day is selected
1668
                     in_array($month, $eventOptions)) {
1669
                        $event['event_start'] = $occurEventStart;
1670
                        $event['event_end']   = $occurEventEnd;
1671
1672
                        $recuEvents[] = $event;
1673
                    } elseif ($occurEventStart > $periodEnd) {
1674
                        break;
1675
                    }
1676
1677
                    if (13 == ++$month) {
1678
                        $month = 1;
1679
                        ++$year;
1680
                        ++$nbOccur;
1681
                    }
1682
                }
1683
1684
                break;
1685
1686
        }
1687
1688
        return $recuEvents;
1689
    }
1690
1691
    //-----------------------------------------------------------------
1692
1693
    /**
1694
     * @param $month
1695
     * @param $year
1696
     * @param $dayCode
1697
     *
1698
     * @return int
0 ignored issues
show
Documentation introduced by
Should the return type not be integer|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
1699
     */
1700
    public function getOccurTS($month, $year, $dayCode)
1701
    {
1702
        if (0 === strpos($dayCode, 'MD')) {
1703
            if ('' != substr($dayCode, 2)) {
1704
                return mktime(0, 0, 0, $month, substr($dayCode, 2), $year);
1705
            } else {
1706
                return 0;
1707
            }
1708
        } else {
1709
            switch ($dayCode) {
1710
1711 View Code Duplication
                case '1SU':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1712
1713
                    $ts        = mktime(0, 0, 0, $month, 1, $year);
1714
                    $dayOfWeek = date('w', $ts);
1715
                    $ts        = (0 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1716
                    $i         = 0;
1717
                    while (0 != $dayOfWeek % 7) {
1718
                        ++$dayOfWeek;
1719
                        ++$i;
1720
                    }
1721
1722
                    return $ts + (_EXTCAL_TS_DAY * $i);
1723
1724
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1725
1726 View Code Duplication
                case '1MO':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1727
1728
                    $ts        = mktime(0, 0, 0, $month, 1, $year);
1729
                    $dayOfWeek = date('w', $ts);
1730
                    $ts        = (1 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1731
                    $i         = 0;
1732
                    while (1 != $dayOfWeek % 7) {
1733
                        ++$dayOfWeek;
1734
                        ++$i;
1735
                    }
1736
1737
                    return $ts + (_EXTCAL_TS_DAY * $i);
1738
1739
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1740
1741 View Code Duplication
                case '1TU':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1742
1743
                    $ts        = mktime(0, 0, 0, $month, 1, $year);
1744
                    $dayOfWeek = date('w', $ts);
1745
                    $ts        = (2 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1746
                    $i         = 0;
1747
                    while (2 != $dayOfWeek % 7) {
1748
                        ++$dayOfWeek;
1749
                        ++$i;
1750
                    }
1751
1752
                    return $ts + (_EXTCAL_TS_DAY * $i);
1753
1754
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1755
1756 View Code Duplication
                case '1WE':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1757
1758
                    $ts        = mktime(0, 0, 0, $month, 1, $year);
1759
                    $dayOfWeek = date('w', $ts);
1760
                    $ts        = (3 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1761
                    $i         = 0;
1762
                    while (3 != $dayOfWeek % 7) {
1763
                        ++$dayOfWeek;
1764
                        ++$i;
1765
                    }
1766
1767
                    return $ts + (_EXTCAL_TS_DAY * $i);
1768
1769
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1770
1771 View Code Duplication
                case '1TH':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1772
1773
                    $ts        = mktime(0, 0, 0, $month, 1, $year);
1774
                    $dayOfWeek = date('w', $ts);
1775
                    $ts        = (4 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1776
                    $i         = 0;
1777
                    while (4 != $dayOfWeek % 7) {
1778
                        ++$dayOfWeek;
1779
                        ++$i;
1780
                    }
1781
1782
                    return $ts + (_EXTCAL_TS_DAY * $i);
1783
1784
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1785
1786 View Code Duplication
                case '1FR':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1787
1788
                    $ts        = mktime(0, 0, 0, $month, 1, $year);
1789
                    $dayOfWeek = date('w', $ts);
1790
                    $ts        = (5 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1791
                    $i         = 0;
1792
                    while (5 != $dayOfWeek % 7) {
1793
                        ++$dayOfWeek;
1794
                        ++$i;
1795
                    }
1796
1797
                    return $ts + (_EXTCAL_TS_DAY * $i);
1798
1799
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1800
1801 View Code Duplication
                case '1SA':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1802
1803
                    $ts        = mktime(0, 0, 0, $month, 1, $year);
1804
                    $dayOfWeek = date('w', $ts);
1805
                    $ts        = (6 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1806
                    $i         = 0;
1807
                    while (6 != $dayOfWeek % 7) {
1808
                        ++$dayOfWeek;
1809
                        ++$i;
1810
                    }
1811
1812
                    return $ts + (_EXTCAL_TS_DAY * $i);
1813
1814
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1815
1816 View Code Duplication
                case '2SU':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1817
1818
                    $ts        = mktime(0, 0, 0, $month, 7, $year);
1819
                    $dayOfWeek = date('w', $ts);
1820
                    $ts        = (0 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1821
                    $i         = 0;
1822
                    while (0 != $dayOfWeek % 7) {
1823
                        ++$dayOfWeek;
1824
                        ++$i;
1825
                    }
1826
1827
                    return $ts + (_EXTCAL_TS_DAY * $i);
1828
1829
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1830
1831 View Code Duplication
                case '2MO':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1832
1833
                    $ts        = mktime(0, 0, 0, $month, 7, $year);
1834
                    $dayOfWeek = date('w', $ts);
1835
                    $ts        = (1 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1836
                    $i         = 0;
1837
                    while (1 != $dayOfWeek % 7) {
1838
                        ++$dayOfWeek;
1839
                        ++$i;
1840
                    }
1841
1842
                    return $ts + (_EXTCAL_TS_DAY * $i);
1843
1844
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1845
1846 View Code Duplication
                case '2TU':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1847
1848
                    $ts        = mktime(0, 0, 0, $month, 7, $year);
1849
                    $dayOfWeek = date('w', $ts);
1850
                    $ts        = (2 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1851
                    $i         = 0;
1852
                    while (2 != $dayOfWeek % 7) {
1853
                        ++$dayOfWeek;
1854
                        ++$i;
1855
                    }
1856
1857
                    return $ts + (_EXTCAL_TS_DAY * $i);
1858
1859
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1860
1861 View Code Duplication
                case '2WE':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1862
1863
                    $ts        = mktime(0, 0, 0, $month, 7, $year);
1864
                    $dayOfWeek = date('w', $ts);
1865
                    $ts        = (3 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1866
                    $i         = 0;
1867
                    while (3 != $dayOfWeek % 7) {
1868
                        ++$dayOfWeek;
1869
                        ++$i;
1870
                    }
1871
1872
                    return $ts + (_EXTCAL_TS_DAY * $i);
1873
1874
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1875
1876 View Code Duplication
                case '2TH':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1877
1878
                    $ts        = mktime(0, 0, 0, $month, 7, $year);
1879
                    $dayOfWeek = date('w', $ts);
1880
                    $ts        = (4 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1881
                    $i         = 0;
1882
                    while (4 != $dayOfWeek % 7) {
1883
                        ++$dayOfWeek;
1884
                        ++$i;
1885
                    }
1886
1887
                    return $ts + (_EXTCAL_TS_DAY * $i);
1888
1889
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1890
1891 View Code Duplication
                case '2FR':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1892
1893
                    $ts        = mktime(0, 0, 0, $month, 7, $year);
1894
                    $dayOfWeek = date('w', $ts);
1895
                    $ts        = (5 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1896
                    $i         = 0;
1897
                    while (5 != $dayOfWeek % 7) {
1898
                        ++$dayOfWeek;
1899
                        ++$i;
1900
                    }
1901
1902
                    return $ts + (_EXTCAL_TS_DAY * $i);
1903
1904
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1905
1906 View Code Duplication
                case '2SA':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1907
1908
                    $ts        = mktime(0, 0, 0, $month, 7, $year);
1909
                    $dayOfWeek = date('w', $ts);
1910
                    $ts        = (6 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1911
                    $i         = 0;
1912
                    while (6 != $dayOfWeek % 7) {
1913
                        ++$dayOfWeek;
1914
                        ++$i;
1915
                    }
1916
1917
                    return $ts + (_EXTCAL_TS_DAY * $i);
1918
1919
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1920
1921 View Code Duplication
                case '3SU':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1922
1923
                    $ts        = mktime(0, 0, 0, $month, 14, $year);
1924
                    $dayOfWeek = date('w', $ts);
1925
                    $ts        = (0 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1926
                    $i         = 0;
1927
                    while (0 != $dayOfWeek % 7) {
1928
                        ++$dayOfWeek;
1929
                        ++$i;
1930
                    }
1931
1932
                    return $ts + (_EXTCAL_TS_DAY * $i);
1933
1934
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1935
1936 View Code Duplication
                case '3MO':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1937
1938
                    $ts        = mktime(0, 0, 0, $month, 14, $year);
1939
                    $dayOfWeek = date('w', $ts);
1940
                    $ts        = (1 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1941
                    $i         = 0;
1942
                    while (1 != $dayOfWeek % 7) {
1943
                        ++$dayOfWeek;
1944
                        ++$i;
1945
                    }
1946
1947
                    return $ts + (_EXTCAL_TS_DAY * $i);
1948
1949
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1950
1951 View Code Duplication
                case '3TU':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1952
1953
                    $ts        = mktime(0, 0, 0, $month, 14, $year);
1954
                    $dayOfWeek = date('w', $ts);
1955
                    $ts        = (2 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1956
                    $i         = 0;
1957
                    while (2 != $dayOfWeek % 7) {
1958
                        ++$dayOfWeek;
1959
                        ++$i;
1960
                    }
1961
1962
                    return $ts + (_EXTCAL_TS_DAY * $i);
1963
1964
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1965
1966 View Code Duplication
                case '3WE':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1967
1968
                    $ts        = mktime(0, 0, 0, $month, 14, $year);
1969
                    $dayOfWeek = date('w', $ts);
1970
                    $ts        = (3 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1971
                    $i         = 0;
1972
                    while (3 != $dayOfWeek % 7) {
1973
                        ++$dayOfWeek;
1974
                        ++$i;
1975
                    }
1976
1977
                    return $ts + (_EXTCAL_TS_DAY * $i);
1978
1979
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1980
1981 View Code Duplication
                case '3TH':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1982
1983
                    $ts        = mktime(0, 0, 0, $month, 14, $year);
1984
                    $dayOfWeek = date('w', $ts);
1985
                    $ts        = (4 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1986
                    $i         = 0;
1987
                    while (4 != $dayOfWeek % 7) {
1988
                        ++$dayOfWeek;
1989
                        ++$i;
1990
                    }
1991
1992
                    return $ts + (_EXTCAL_TS_DAY * $i);
1993
1994
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1995
1996 View Code Duplication
                case '3FR':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1997
1998
                    $ts        = mktime(0, 0, 0, $month, 14, $year);
1999
                    $dayOfWeek = date('w', $ts);
2000
                    $ts        = (5 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
2001
                    $i         = 0;
2002
                    while (5 != $dayOfWeek % 7) {
2003
                        ++$dayOfWeek;
2004
                        ++$i;
2005
                    }
2006
2007
                    return $ts + (_EXTCAL_TS_DAY * $i);
2008
2009
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
2010
2011 View Code Duplication
                case '3SA':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
2012
2013
                    $ts        = mktime(0, 0, 0, $month, 14, $year);
2014
                    $dayOfWeek = date('w', $ts);
2015
                    $ts        = (6 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
2016
                    $i         = 0;
2017
                    while (6 != $dayOfWeek % 7) {
2018
                        ++$dayOfWeek;
2019
                        ++$i;
2020
                    }
2021
2022
                    return $ts + (_EXTCAL_TS_DAY * $i);
2023
2024
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
2025
2026 View Code Duplication
                case '4SU':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
2027
2028
                    $ts        = mktime(0, 0, 0, $month, 21, $year);
2029
                    $dayOfWeek = date('w', $ts);
2030
                    $ts        = (0 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
2031
                    $i         = 0;
2032
                    while (0 != $dayOfWeek % 7) {
2033
                        ++$dayOfWeek;
2034
                        ++$i;
2035
                    }
2036
2037
                    return $ts + (_EXTCAL_TS_DAY * $i);
2038
2039
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
2040
2041 View Code Duplication
                case '4MO':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
2042
2043
                    $ts        = mktime(0, 0, 0, $month, 21, $year);
2044
                    $dayOfWeek = date('w', $ts);
2045
                    $ts        = (1 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
2046
                    $i         = 0;
2047
                    while (1 != $dayOfWeek % 7) {
2048
                        ++$dayOfWeek;
2049
                        ++$i;
2050
                    }
2051
2052
                    return $ts + (_EXTCAL_TS_DAY * $i);
2053
2054
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
2055
2056 View Code Duplication
                case '4TU':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
2057
2058
                    $ts        = mktime(0, 0, 0, $month, 21, $year);
2059
                    $dayOfWeek = date('w', $ts);
2060
                    $ts        = (2 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
2061
                    $i         = 0;
2062
                    while (2 != $dayOfWeek % 7) {
2063
                        ++$dayOfWeek;
2064
                        ++$i;
2065
                    }
2066
2067
                    return $ts + (_EXTCAL_TS_DAY * $i);
2068
2069
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
2070
2071 View Code Duplication
                case '4WE':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
2072
2073
                    $ts        = mktime(0, 0, 0, $month, 21, $year);
2074
                    $dayOfWeek = date('w', $ts);
2075
                    $ts        = (3 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
2076
                    $i         = 0;
2077
                    while (3 != $dayOfWeek % 7) {
2078
                        ++$dayOfWeek;
2079
                        ++$i;
2080
                    }
2081
2082
                    return $ts + (_EXTCAL_TS_DAY * $i);
2083
2084
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
2085
2086 View Code Duplication
                case '4TH':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
2087
2088
                    $ts        = mktime(0, 0, 0, $month, 21, $year);
2089
                    $dayOfWeek = date('w', $ts);
2090
                    $ts        = (4 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
2091
                    $i         = 0;
2092
                    while (4 != $dayOfWeek % 7) {
2093
                        ++$dayOfWeek;
2094
                        ++$i;
2095
                    }
2096
2097
                    return $ts + (_EXTCAL_TS_DAY * $i);
2098
2099
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
2100
2101 View Code Duplication
                case '4FR':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
2102
2103
                    $ts        = mktime(0, 0, 0, $month, 21, $year);
2104
                    $dayOfWeek = date('w', $ts);
2105
                    $ts        = (5 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
2106
                    $i         = 0;
2107
                    while (5 != $dayOfWeek % 7) {
2108
                        ++$dayOfWeek;
2109
                        ++$i;
2110
                    }
2111
2112
                    return $ts + (_EXTCAL_TS_DAY * $i);
2113
2114
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
2115
2116 View Code Duplication
                case '4SA':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
2117
2118
                    $ts        = mktime(0, 0, 0, $month, 21, $year);
2119
                    $dayOfWeek = date('w', $ts);
2120
                    $ts        = (6 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
2121
                    $i         = 0;
2122
                    while (6 != $dayOfWeek % 7) {
2123
                        ++$dayOfWeek;
2124
                        ++$i;
2125
                    }
2126
2127
                    return $ts + (_EXTCAL_TS_DAY * $i);
2128
2129
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
2130
2131 View Code Duplication
                case '-1SU':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
2132
2133
                    $ts        = mktime(0, 0, 0, $month, date('t', mktime(0, 0, 0, $month, 1, $year)), $year);
2134
                    $dayOfWeek = date('w', $ts);
2135
                    $i         = 0;
2136
                    while (0 != $dayOfWeek % 7) {
2137
                        ++$dayOfWeek;
2138
                        ++$i;
2139
                    }
2140
                    if (0 == $i) {
2141
                        return $ts;
2142
                    }
2143
2144
                    return $ts + (_EXTCAL_TS_DAY * ($i - 7));
2145
2146
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
2147
2148 View Code Duplication
                case '-1MO':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
2149
2150
                    $ts        = mktime(0, 0, 0, $month, date('t', mktime(0, 0, 0, $month, 1, $year)), $year);
2151
                    $dayOfWeek = date('w', $ts);
2152
                    $i         = 0;
2153
                    while (1 != $dayOfWeek % 7) {
2154
                        ++$dayOfWeek;
2155
                        ++$i;
2156
                    }
2157
                    if (0 == $i) {
2158
                        return $ts;
2159
                    }
2160
2161
                    return $ts + (_EXTCAL_TS_DAY * ($i - 7));
2162
2163
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
2164
2165 View Code Duplication
                case '-1TU':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
2166
2167
                    $ts        = mktime(0, 0, 0, $month, date('t', mktime(0, 0, 0, $month, 1, $year)), $year);
2168
                    $dayOfWeek = date('w', $ts);
2169
                    $i         = 0;
2170
                    while (2 != $dayOfWeek % 7) {
2171
                        ++$dayOfWeek;
2172
                        ++$i;
2173
                    }
2174
                    if (0 == $i) {
2175
                        return $ts;
2176
                    }
2177
2178
                    return $ts + (_EXTCAL_TS_DAY * ($i - 7));
2179
2180
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
2181
2182 View Code Duplication
                case '-1WE':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
2183
2184
                    $ts        = mktime(0, 0, 0, $month, date('t', mktime(0, 0, 0, $month, 1, $year)), $year);
2185
                    $dayOfWeek = date('w', $ts);
2186
                    $i         = 0;
2187
                    while (3 != $dayOfWeek % 7) {
2188
                        ++$dayOfWeek;
2189
                        ++$i;
2190
                    }
2191
                    if (0 == $i) {
2192
                        return $ts;
2193
                    }
2194
2195
                    return $ts + (_EXTCAL_TS_DAY * ($i - 7));
2196
2197
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
2198
2199 View Code Duplication
                case '-1TH':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
2200
2201
                    $ts        = mktime(0, 0, 0, $month, date('t', mktime(0, 0, 0, $month, 1, $year)), $year);
2202
                    $dayOfWeek = date('w', $ts);
2203
                    $i         = 0;
2204
                    while (4 != $dayOfWeek % 7) {
2205
                        ++$dayOfWeek;
2206
                        ++$i;
2207
                    }
2208
                    if (0 == $i) {
2209
                        return $ts;
2210
                    }
2211
2212
                    return $ts + (_EXTCAL_TS_DAY * ($i - 7));
2213
2214
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
2215
2216 View Code Duplication
                case '-1FR':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
2217
2218
                    $ts        = mktime(0, 0, 0, $month, date('t', mktime(0, 0, 0, $month, 1, $year)), $year);
2219
                    $dayOfWeek = date('w', $ts);
2220
                    $i         = 0;
2221
                    while (5 != $dayOfWeek % 7) {
2222
                        ++$dayOfWeek;
2223
                        ++$i;
2224
                    }
2225
                    if (0 == $i) {
2226
                        return $ts;
2227
                    }
2228
2229
                    return $ts + (_EXTCAL_TS_DAY * ($i - 7));
2230
2231
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
2232
2233 View Code Duplication
                case '-1SA':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
2234
2235
                    $ts        = mktime(0, 0, 0, $month, date('t', mktime(0, 0, 0, $month, 1, $year)), $year);
2236
                    $dayOfWeek = date('w', $ts);
2237
                    $i         = 0;
2238
                    while (6 != $dayOfWeek % 7) {
2239
                        ++$dayOfWeek;
2240
                        ++$i;
2241
                    }
2242
                    if (0 == $i) {
2243
                        return $ts;
2244
                    }
2245
2246
                    return $ts + (_EXTCAL_TS_DAY * ($i - 7));
2247
2248
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
2249
2250
                default:
2251
                    return 0;
2252
2253
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
2254
2255
            }
2256
        }
2257
    }
2258
2259
    /*************************************************************************
2260
     *
2261
     ************************************************************************
2262
     * @param $year
2263
     * @param $month
2264
     * @param $day
2265
     * @param $cat
2266
     * @param $searchExp
2267
     * @param $andor
2268
     * @param $orderBy
2269
     * @return array
2270
     */
2271
    public function getSearchEvent2($year, $month, $day, $cat, $searchExp, $andor, $orderBy)
2272
    {
2273
        global $xoopsDB, $xoopsUser;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
2274
2275
        if (isset($xoopsUser)) {
2276
            $userId = $xoopsUser->getVar('uid');
2277
            $result = $this->getSearchEvents($year, $month, $day, $cat, $searchExp, $andor, $orderBy, 0, 0, $userId, $xoopsUser);
2278
        } else {
2279
            $result = $this->getSearchEvents($year, $month, $day, $cat, $searchExp, $andor, $orderBy, 0, 0);
2280
        }
2281
2282
        $ret = [];
2283
        while ($myrow = $xoopsDB->fetchArray($result)) {
2284
            $myrow['cat']['cat_name']        = $myrow['cat_name'];
2285
            $myrow['cat']['cat_color']       = $myrow['cat_color'];
2286
            $myrow['cat']['cat_light_color'] = Extcal\Utility::getLighterColor($myrow['cat']['cat_color'], _EXTCAL_INFOBULLE_RGB_MIN, _EXTCAL_INFOBULLE_RGB_MAX);
2287
            if ('' == $myrow['event_icone']) {
2288
                $myrow['event_icone'] = $myrow['cat']['cat_icone'];
2289
            }
2290
            $ret[] = $myrow;
2291
        }
2292
2293
        return $ret;
2294
    }
2295
2296
    //-----------------------------------------------------------
2297
2298
    /**
2299
     * @param int    $year
2300
     * @param int    $month
2301
     * @param int    $day
2302
     * @param int    $cat
2303
     * @param        $queryarray
2304
     * @param        $andor
2305
     * @param        $orderBy
2306
     * @param int    $limit
2307
     * @param int    $offset
2308
     * @param int    $userId
2309
     * @param string $user
2310
     *
2311
     * @return mixed
2312
     */
2313
    public function getSearchEvents(
2314
        $year = 0,
2315
        $month = 0,
2316
        $day = 0,
2317
        $cat = 0,
2318
        $queryarray,
2319
        $andor,
2320
        $orderBy,
2321
        $limit = 0,
2322
        $offset = 0,
2323
        $userId = 0,
2324
        $user = '')
2325
    {
2326
        global $xoopsDB;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
2327
2328
        //echo "<hr>{$andor}-{$limit}-{$offset}-{$userId}-{$user}<br>{$criteresPlus}";
2329
        $tEvent = $xoopsDB->prefix('extcal_event') . ' AS te';
2330
        $tCat   = $xoopsDB->prefix('extcal_cat') . ' AS tc';
2331
2332
        $sql = 'SELECT te.*, tc.cat_name , tc.cat_color, ' . 'year(FROM_UNIXTIME(event_start)) AS year,' . 'month(FROM_UNIXTIME(event_start)) AS month,' . 'day(FROM_UNIXTIME(event_start)) AS day' . " FROM {$tEvent}, {$tCat}";
2333
        //---------------------------------------------------
2334
        $tw   = [];
2335
        $tw[] = 'te.cat_id = tc.cat_id';
2336
        $tw[] = 'event_approved = 1';
2337
2338
        $authorizedAccessCats = $this->_extcalPerm->getAuthorizedCat($user, 'extcal_cat_view');
2339
        $inCat                = 'te.cat_id IN (0)';
2340
        if (count($authorizedAccessCats) > 0) {
2341
            $inCat = 'te.cat_id IN (' . implode(',', $authorizedAccessCats) . ')';
2342
        }
2343
        //echo $tw[count($tw)-1];
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
2344
2345
        if (0 != $userId) {
2346
            $tw[] .= "({$inCat} OR event_submitter = {$userId} )";
2347
        } else {
2348
            $tw[] = $inCat;
2349
        }
2350
        //--------------------------------------------------------
2351
        if ($cat > 0) {
2352
            $tw[] .= "te.cat_id = {$cat}";
2353
        }
2354
        if ($year > 0) {
2355
            $tw[] .= "year(FROM_UNIXTIME(event_start)) = {$year}";
2356
        }
2357
        if ($month > 0) {
2358
            $tw[] .= "month(FROM_UNIXTIME(event_start)) = {$month}";
2359
        }
2360
        if ($day > 0) {
2361
            $tw[] .= "day(FROM_UNIXTIME(event_start)) = {$day}";
2362
        }
2363
2364
        //echoArray($queryarray,false);
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
2365
        if (!is_array($queryarray)) {
2366
            $queryarray = (('' != $queryarray) ? explode(' ', $queryarray) : '');
2367
        }
2368
2369
        if (is_array($queryarray)) {
2370
            $tFields = [
2371
                'te.event_title',
2372
                'te.event_desc',
2373
                'te.event_contact',
2374
                'te.event_address',
2375
                'tc.cat_name',
2376
            ];
2377
            $t       = [];
0 ignored issues
show
Unused Code introduced by
$t is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2378
            foreach ($queryarray as $i => $iValue) {
2379
                $t1[] = " %1\$s LIKE '#{$queryarray[$i]}#' ";
0 ignored issues
show
Coding Style Comprehensibility introduced by
$t1 was never initialized. Although not strictly required by PHP, it is generally a good practice to add $t1 = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
2380
            }
2381
2382
            $flt = '(' . implode(" {$andor} ", $t1) . ')';
0 ignored issues
show
Bug introduced by
The variable $t1 does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
2383
2384
            $t = [];
2385
            foreach ($tFields as $h => $hValue) {
2386
                $t[] = sprintf($flt, $tFields[$h]);
2387
            }
2388
2389
            $filtre = implode(' OR ', $t);
2390
            $filtre = str_replace('#', '%', $filtre);
2391
            $tw[]   = '(' . $filtre . ')';
2392
        }
2393
2394
        $sql .= ' WHERE ' . implode(' AND ', $tw);
2395
        //------------------------------------------------------------
2396
        if (count($orderBy) > 0) {
2397
            $t = [];
2398
            foreach ($orderBy as $hValue) {
2399
                if ('' != $hValue) {
2400
                    $t[] = $hValue;
2401
                }
2402
            }
2403
            if (count($t) > 0) {
2404
                $sql .= ' ORDER BY ' . implode(',', $t);
2405
            }
2406
        }
2407
2408
        //----------------------------------------------------------------
2409
2410
        $result = $xoopsDB->query($sql, $limit, $offset);
2411
2412
        // echo "<hr>{$sql}<hr>";
2413
        return $result;
2414
    }
2415
2416
    //-----------------------------------------------------------
2417
2418
    /**
2419
     * @param $queryarray
2420
     * @param $andor
2421
     * @param $limit
2422
     * @param $offset
2423
     * @param $userId
2424
     * @param $user
2425
     *
2426
     * @return mixed
2427
     */
2428
    public function getSearchEvent($queryarray, $andor, $limit, $offset, $userId, $user)
2429
    {
2430
        global $xoopsDB;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
2431
2432
        $result = $this->getSearchEvents(0, 0, 0, 0, $queryarray, $andor, ['event_id DESC']);
2433
2434
        $i = 0;
2435 View Code Duplication
        while ($myrow = $xoopsDB->fetchArray($result)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2436
            $ret[$i]['image'] = 'assets/images/icons/extcal.gif';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$ret was never initialized. Although not strictly required by PHP, it is generally a good practice to add $ret = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
2437
            $ret[$i]['link']  = 'event.php?event=' . $myrow['event_id'];
0 ignored issues
show
Bug introduced by
The variable $ret does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
2438
            $ret[$i]['title'] = $myrow['event_title'];
2439
            $ret[$i]['time']  = $myrow['event_submitdate'];
2440
            $ret[$i]['uid']   = $myrow['event_submitter'];
2441
            ++$i;
2442
        }
2443
2444
        return $ret;
2445
    }
2446
2447
    /**
2448
     * @param        $queryarray
2449
     * @param        $andor
2450
     * @param        $limit
2451
     * @param        $offset
2452
     * @param        $userId
2453
     * @param        $user
2454
     * @param string $criteresPlus
2455
     * @param bool   $xoopsSearch
2456
     *
2457
     * @return array
2458
     */
2459
    public function getSearchEvent3(
2460
        $queryarray,
2461
        $andor,
2462
        $limit,
2463
        $offset,
2464
        $userId,
2465
        $user,
2466
        $criteresPlus = '',
2467
        $xoopsSearch = true)
2468
    {
2469
        global $xoopsDB;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
2470
        //echo "<hr>{$andor}-{$limit}-{$offset}-{$userId}-{$user}<br>{$criteresPlus}";
2471
2472
        //        if ($cols == '') {
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
2473
        //            $cols = 'event_id, event_title, event_submitter, event_submitdate';
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
2474
        //        }
2475
        $tEvent = $xoopsDB->prefix('extcal_event');
2476
        $tCat   = $xoopsDB->prefix('extcal_cat');
2477
        $sql    = "SELECT {$tEvent}.*, {$tCat}.cat_name AS categorie, {$tCat}.cat_color " . " FROM {$tEvent}, {$tCat}" . " WHERE {$tEvent}.cat_id = {$tCat}.cat_id AND event_approved = '1'";
2478
2479
        $authorizedAccessCats = $this->_extcalPerm->getAuthorizedCat($user, 'extcal_cat_view');
2480
        $count                = count($authorizedAccessCats);
2481
        if ($count > 0) {
2482
            $in = '(' . $authorizedAccessCats[0];
2483
            array_shift($authorizedAccessCats);
2484
            foreach ($authorizedAccessCats as $authorizedAccessCat) {
2485
                $in .= ',' . $authorizedAccessCat;
2486
            }
2487
            $in .= ')';
2488
        } else {
2489
            $in = '(0)';
2490
        }
2491
        $sql .= " AND {$tEvent}.cat_id IN " . $in . '';
2492
        if (0 != $userId) {
2493
            $sql .= " AND event_submitter = '" . $userId . "'";
2494
        }
2495
2496
        //echoArray($queryarray,false);
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
2497
        if (is_array($queryarray)) {
2498
            /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
44% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
2499
            $sql .= " AND ((event_title LIKE '%$queryarray[0]%' OR event_desc LIKE '%$queryarray[0]%' OR event_contact LIKE '%$queryarray[0]%' OR event_address LIKE '%$queryarray[0]%')";
2500
            for ($i = 1; $i < $count; ++$i) {
2501
                $sql .= " $andor ";
2502
                $sql .= "(event_title LIKE '%$queryarray[0]%' OR event_desc LIKE '%$queryarray[0]%' OR event_contact LIKE '%$queryarray[0]%' OR event_address LIKE '%$queryarray[0]%')";
2503
            }
2504
            $sql .= ") ";
2505
            */
2506
2507
            $tFields = ['event_title', 'event_desc', 'event_contact', 'event_address', 'cat_name'];
2508
            $t       = [];
0 ignored issues
show
Unused Code introduced by
$t is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2509
            foreach ($queryarray as $i => $iValue) {
2510
                $t1[] = " %1\$s LIKE '#{$queryarray[$i]}#' ";
0 ignored issues
show
Coding Style Comprehensibility introduced by
$t1 was never initialized. Although not strictly required by PHP, it is generally a good practice to add $t1 = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
2511
            }
2512
2513
            $flt = '(' . implode(" {$andor} ", $t1) . ')';
0 ignored issues
show
Bug introduced by
The variable $t1 does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
2514
2515
            $t = [];
2516
            foreach ($tFields as $h => $hValue) {
2517
                $t[] = sprintf($flt, $tFields[$h]);
2518
            }
2519
2520
            $filtre = implode(' OR ', $t);
2521
            $filtre = str_replace('#', '%', $filtre);
2522
            $sql    .= " AND ($filtre)";
2523
        }
2524
2525
        if ('' != $criteresPlus) {
2526
            $sql .= ' AND ' . $criteresPlus;
2527
        }
2528
        $sql .= ' ORDER BY event_id DESC';
2529
2530
        $result = $xoopsDB->query($sql, $limit, $offset);
2531
        $ret    = [];
2532
        $i      = 0;
2533
        if ($xoopsSearch) {
2534 View Code Duplication
            while ($myrow = $xoopsDB->fetchArray($result)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2535
                $ret[$i]['image'] = 'assets/images/icons/extcal.gif';
2536
                $ret[$i]['link']  = 'event.php?event=' . $myrow['event_id'];
2537
                $ret[$i]['title'] = $myrow['event_title'];
2538
                $ret[$i]['time']  = $myrow['event_submitdate'];
2539
                $ret[$i]['uid']   = $myrow['event_submitter'];
2540
                ++$i;
2541
            }
2542
        } else {
2543
            while ($myrow = $xoopsDB->fetchArray($result)) {
2544
                $myrow['cat']['cat_name']  = $myrow['cat_name'];
2545
                $myrow['cat']['cat_color'] = $myrow['cat_color'];
2546
                $ret[]                     = $myrow;
2547
                ++$i;
2548
            }
2549
        }
2550
2551
        return $ret;
2552
    }
2553
2554
    /**
2555
     * @param $event
2556
     * @param $eventsArray
2557
     * @param $startPeriod
2558
     * @param $endPeriod
2559
     */
2560
    public function addEventToCalArray(&$event, &$eventsArray, $startPeriod, $endPeriod)
2561
    {
2562
        global $timeHandler, $xoopsUser, $month, $year;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
2563
2564
        // Calculating the start and the end of the event
2565
        $startEvent = $event['event_start'];
2566
        $endEvent   = $event['event_end'];
2567
2568
        // This event start before this month and finish after
2569
        if ($startEvent < $startPeriod && $endEvent > $endPeriod) {
2570
            $endFor = date('t', mktime(0, 0, 0, $month, 1, $year));
2571
            for ($i = 1; $i <= $endFor; ++$i) {
2572
                $event['status']   = 'middle';
2573
                $eventsArray[$i][] = $event;
2574
            }
2575
            // This event start before this month and finish during
2576
        } else {
2577
            if ($startEvent < $startPeriod) {
2578
                $endFor = date('j', $endEvent);
2579 View Code Duplication
                for ($i = 1; $i <= $endFor; ++$i) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2580
                    $event['status']   = ($i != $endFor) ? 'middle' : 'end';
2581
                    $eventsArray[$i][] = $event;
2582
                }
2583
                // This event start during this month and finish after
2584
            } else {
2585
                if ($endEvent > $endPeriod) {
2586
                    $startFor = date('j', $startEvent);
2587
                    $endFor   = date('t', mktime(0, 0, 0, $month, 1, $year));
2588 View Code Duplication
                    for ($i = $startFor; $i <= $endFor; ++$i) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2589
                        $event['status']   = ($i == $startFor) ? 'start' : 'middle';
2590
                        $eventsArray[$i][] = $event;
2591
                    }
2592
                    // This event start and finish during this month
2593
                } else {
2594
                    $startFor = date('j', $startEvent);
2595
                    $endFor   = date('j', $endEvent);
2596
                    for ($i = $startFor; $i <= $endFor; ++$i) {
2597
                        if ($startFor == $endFor) {
2598
                            $event['status'] = 'single';
2599
                        } else {
2600
                            if ($i == $startFor) {
2601
                                $event['status'] = 'start';
2602
                            } else {
2603
                                if ($i == $endFor) {
2604
                                    $event['status'] = 'end';
2605
                                } else {
2606
                                    $event['status'] = 'middle';
2607
                                }
2608
                            }
2609
                        }
2610
                        $eventsArray[$i][] = $event;
2611
                    }
2612
                }
2613
            }
2614
        }
2615
    }
2616
2617
    //-------------------------------------------------
2618
} // -------- Fin e la classe ---------------------
2619