Completed
Branch master (55a138)
by Michael
03:21
created

EventHandler::getEventsUniques()   D

Complexity

Conditions 17
Paths 224

Size

Total Lines 75
Code Lines 48

Duplication

Lines 20
Ratio 26.67 %

Importance

Changes 0
Metric Value
cc 17
eloc 48
nc 224
nop 1
dl 20
loc 75
rs 4.4764
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 33 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
 * You may not change or alter any portion of this comment or credits
4
 * of supporting developers from this source code or any supporting source code
5
 * which is considered copyrighted (c) material of the original comment or credit authors.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * @copyright    {@link https://xoops.org/ XOOPS Project}
14
 * @license      {@link http://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
15
 * @package      extcal
16
 * @since
17
 * @author       XOOPS Development Team,
18
 */
19
20
use Punic\Exception;
21
use XoopsModules\Extcal;
22
23
// 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...
24
25
26
require_once __DIR__ . '/../include/constantes.php';
27
28
29
30
/**
31
 * Class EventHandler.
32
 */
33
class EventHandler extends ExtcalPersistableObjectHandler
34
{
35
    private $_extcalPerm;
36
    private $_extcalTime;
37
    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...
38
39
    /**
40
     * @param $db
41
     */
42
    public function __construct(\XoopsDatabase $db)
43
    {
44
        $this->_extcalPerm = Extcal\Perm::getHandler();
45
        $this->_extcalTime = Extcal\Time::getHandler();
46
        //         $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...
47
        //         $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...
48
        parent::__construct($db, 'extcal_event', Event::class, 'event_id');
49
    }
50
51
    /**
52
     * @param $data
53
     *
54
     * @return bool
55
     */
56 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...
57
    {
58
        $event = $this->create();
59
        $this->_checkDate($data);
60
        $this->_userTimeToServerTime($data);
61
        $this->_addRecurValue($data);
62
        $event->setVars($data);
63
64
        return $this->insert($event, true);
65
    }
66
67
    /**
68
     * @param $data
69
     *
70
     * @return XoopsObject
0 ignored issues
show
Documentation introduced by
Should the return type not be \XoopsObject?

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...
71
     */
72
    public function createEventForPreview($data)
73
    {
74
        $event = $this->create();
75
        $this->_checkDate($data);
76
        $this->_addRecurValue($data);
77
        $event->setVars($data);
78
79
        return $event;
80
    }
81
82
    /**
83
     * @param $eventId
84
     * @param $data
85
     *
86
     * @return bool
87
     */
88 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...
89
    {
90
        $event = $this->get($eventId);
91
        $this->_checkDate($data);
92
        $this->_userTimeToServerTime($data);
93
        $this->_addRecurValue($data);
94
        $event->setVars($data);
95
96
        return $this->insert($event);
97
    }
98
99
    /**
100
     * @param $eventId
101
     */
102
    public function deleteEvent($eventId)
103
    {
104
        /* TODO :
105
           - Delete who's going
106
           - Delete who's not going
107
           - Delete comment
108
           - Delete notifications
109
          */
110
        $this->deleteById($eventId, true);
111
    }
112
113
    /**
114
     * @param null $criteria
115
     * @param bool $force
116
     * @param bool $asObject
117
     */
118
    public function deleteAllEvents($criteria = null, $force = true, $asObject = false)
119
    {
120
        /* TODO :
121
           - Delete who's going
122
           - Delete who's not going
123
           - Delete comment
124
           - Delete notifications
125
          */
126
        $this->deleteAll($criteria, $force, $asObject);
127
    }
128
129
    /**
130
     * @param null $criteria
131
     * @param bool $asObject
132
     *
133
     * @return array
134
     */
135
    public function getAllEvents($criteria = null, $asObject = false)
136
    {
137
        $rst = $this->getObjects($criteria, $asObject);
138
        if ($asObject) {
139
            return $rst;
140
        } else {
141
            return $this->objectToArray($rst);
142
        }
143
    }
144
145
    // Return one approved event selected by his id
146
147
    /**
148
     * @param      $eventId
149
     * @param bool $skipPerm
150
     *
151
     * @return bool
152
     */
153 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...
154
    {
155
        $user = $GLOBALS['xoopsUser'];
156
157
        $criteriaCompo =  new \CriteriaCompo();
158
        $criteriaCompo->add( new \Criteria('event_id', $eventId));
159
        $criteriaCompo->add( new \Criteria('event_approved', 1));
160
        if (!$skipPerm) {
161
            $this->_addCatPermCriteria($criteriaCompo, $user);
162
        }
163
        $ret = $this->getObjects($criteriaCompo);
164
        if (isset($ret[0])) {
165
            return $ret[0];
166
        } else {
167
            return false;
168
        }
169
    }
170
171
    // Return one event selected by his id (approve or not)
172
173
    /**
174
     * @param      $eventId
175
     * @param bool $skipPerm
176
     *
177
     * @return bool
178
     */
179 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...
180
    {
181
        $user = $GLOBALS['xoopsUser'];
182
183
        $criteriaCompo =  new \CriteriaCompo();
184
        $criteriaCompo->add( new \Criteria('event_id', $eventId));
185
        if (!$skipPerm) {
186
            $this->_addCatPermCriteria($criteriaCompo, $user);
187
        }
188
        $ret = $this->getObjects($criteriaCompo);
189
        if (isset($ret[0])) {
190
            return $ret[0];
191
        } else {
192
            return false;
193
        }
194
    }
195
196
    /**
197
     * @param $events
198
     * @param $pattern
199
     */
200
    public function formatEventsDate(&$events, $pattern)
201
    {
202
        $max = count($events);
203
        for ($i = 0; $i < $max; ++$i) {
204
            $this->formatEventDate($events[$i], $pattern);
205
        }
206
    }
207
208
    //  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...
209
    //      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...
210
    //  }
211
    //  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...
212
    //      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...
213
    //  }
214
    //  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...
215
    //      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...
216
    //  }
217
218
    /**
219
     * @param $event
220
     * @param $pattern
221
     */
222
    public function formatEventDate(&$event, $pattern)
223
    {
224
        if (!$event['event_isrecur']) {
225
            $event['formated_event_start'] = $this->_extcalTime->getFormatedDate($pattern, $event['event_start']);
226
            $event['formated_event_end']   = $this->_extcalTime->getFormatedDate($pattern, $event['event_end']);
227
        } else {
228
            $event['formated_event_start'] = $this->_extcalTime->getFormatedDate($pattern, $event['event_start']);
229
            $event['formated_event_end']   = $this->_extcalTime->getFormatedDate($pattern, $event['event_end']);
230
            $event['formated_reccur_rule'] = $this->_extcalTime->getFormatedReccurRule($event['event_recur_rules']);
231
        }
232
        $event['formated_event_submitdate'] = $this->_extcalTime->getFormatedDate($pattern, $event['event_submitdate']);
233
    }
234
235
    //JJD - to valid modif
236
    //     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...
237
    //     {
238
    //
239
    //         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...
240
    //         $data['event_start']
241
    //             =
242
    //             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...
243
    //         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...
244
    //         $data['event_end']
245
    //             = 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...
246
    //
247
    //         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...
248
    //) {
249
    //             $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...
250
    //         }
251
    //
252
    //     }
253
254
    /**
255
     * @param $data
256
     */
257
    public function _checkDate(&$data)
258
    {
259
        $data['event_start'] = strtotime($data['event_start']['date']) + $data['event_start']['time'];
260
        $data['event_end']   = strtotime($data['event_end']['date']) + $data['event_end']['time'];
261
262
        if (0 == $data['have_end'] || $data['event_start'] > $data['event_end']) {
263
            $data['event_end'] = $data['event_start'];
264
        }
265
    }
266
267
    /**
268
     * @param $data
269
     */
270
    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...
271
    {
272
        $user = $GLOBALS['xoopsUser'];
273
274
        $data['event_start'] = userTimeToServerTime($data['event_start'], $this->_extcalTime->_getUserTimeZone($user));
275
        $data['event_end']   = userTimeToServerTime($data['event_end'], $this->_extcalTime->_getUserTimeZone($user));
276
    }
277
278
    /**
279
     * @param $data
280
     */
281
    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...
282
    {
283
        $user = $GLOBALS['xoopsUser'];
284
285
        $data['event_start']      = xoops_getUserTimestamp($data['event_start'], $this->_extcalTime->_getUserTimeZone($user));
286
        $data['event_end']        = xoops_getUserTimestamp($data['event_end'], $this->_extcalTime->_getUserTimeZone($user));
287
        $data['event_submitdate'] = xoops_getUserTimestamp($data['event_submitdate'], $this->_extcalTime->_getUserTimeZone($user));
288
    }
289
290
    /**
291
     * @param $events
292
     */
293
    public function serverTimeToUserTimes(&$events)
294
    {
295
        $max = count($events);
296
297
        for ($i = 0; $i < $max; ++$i) {
298
            $this->serverTimeToUserTime($events[$i]);
299
        }
300
    }
301
302
    /**
303
     * @param $data
304
     */
305
    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...
306
    {
307
        $data['event_isrecur']     = $this->getIsRecur($_POST);
308
        $data['event_recur_rules'] = $this->getRecurRules($_POST);
309
        $data['event_recur_start'] = $this->getRecurStart($data, $_POST);
310
        $data['event_recur_end']   = $this->getRecurEnd($data, $_POST);
311
    }
312
313
    /***************************************************************
314
     * Return events on perioe
315
     **************************************************************
316
     *
317
     * @param $criteres
318
     *
319
     * @return array
320
     */
321
    public function getEventsOnPeriode($criteres)
322
    {
323
        //ext_echoArray($criteres);
324
        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...
325
        $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...
326
327
        $eventsU = $this->getEventsUniques($criteres);
328
        $eventsR = $this->getEventsRecurents($criteres);
329
        $events  = array_merge($eventsU, $eventsR);
330
331
        //      $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...
332
333
        //ext_echoArray($events);
334
335
        //Tri des evennement par date ascendante
336
        $ordre      = [];
337
        $eventArray = [];
338
339
        //        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...
340
        foreach ($events as $k => $v) {
341
            $ordre[] = (int)$v['event_start'];
342
            $this->formatEventDate($v, $extcalConfig['event_date_week']);
343
            //$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...
344
            $v['cat']['cat_light_color'] = Extcal\Utility::getLighterColor($v['cat']['cat_color'], _EXTCAL_INFOBULLE_RGB_MIN, _EXTCAL_INFOBULLE_RGB_MAX);
345
            if ('' == $v['event_icone']) {
346
                $v['event_icone'] = $v['cat']['cat_icone'];
347
            }
348
            $v['event_desc'] = html_entity_decode($v['event_desc']);
349
            $eventArray[]    = $v;
350
        }
351
        array_multisort($eventArray, SORT_ASC, SORT_NUMERIC, $ordre, SORT_ASC, SORT_NUMERIC);
352
353
        return $eventArray;
354
    }
355
356
    /*****************************************************************
357
     *
358
     ****************************************************************
359
     * @param $criteres
360
     * @return array
361
     */
362
    public function getEventsUniques($criteres)
363
    {
364
        $cat = 0;
365
        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...
366
        //        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...
367
        foreach ($criteres as $k => $v) {
368
            $$k = $v;
369
        }
370
        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...
371
            $nbDays = 7;
372
        }
373
        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...
374
            $sens = 'ASC';
375
        }
376
        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...
377
            $externalKeys = ['cat_id'];
378
        }
379
        //------------------------------------------------------
380
        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...
381
382
            case _EXTCAL_EVENTS_CALENDAR_WEEK:
383
                $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...
384
                if (!$extcalConfig['diplay_past_event_cal']) {
385
                    $criteriaCompo->add( new \Criteria('event_end', time(), '>'));
386
                }
387
                break;
388
389
            case _EXTCAL_EVENTS_WEEK:
390 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...
391
                $criteriaCompo = $this->_getEventWeekCriteria($day, $month, $year, $cat, $nbDays);
392
                if (!$extcalConfig['diplay_past_event_list']) {
393
                    $criteriaCompo->add( new \Criteria('event_end', time(), '>'));
394
                }
395
                break;
396
397 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...
398
                $criteriaCompo = $this->_getEventMonthCriteria($month, $year, $cat);
399
400
                if (!$extcalConfig['diplay_past_event_cal']) {
401
                    $criteriaCompo->add( new \Criteria('event_end', time(), '>'));
402
                }
403
                break;
404
405 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...
406
                $criteriaCompo = $this->_getEventMonthCriteria($month, $year, $cat);
407
408
                if (!$extcalConfig['diplay_past_event_list']) {
409
                    $criteriaCompo->add( new \Criteria('event_end', time(), '>'));
410
                }
411
                break;
412
413
            case _EXTCAL_EVENTS_DAY:
414
                $criteriaCompo = $this->_getEventDayCriteria($day, $month, $year, $cat);
415
416
                break;
417
418
            case _EXTCAL_EVENTS_YEAR:
419
                $criteriaCompo = $this->_getEventYearCriteria($year, $cat);
420
                break;
421
422
            case _EXTCAL_EVENTS_UPCOMING:
423
                $criteriaCompo = $this->_getEventWeekCriteria($day, $month, $year, $cat, $nbDays);
424
                break;
425
426
        }
427
        //--------------------------------------------------------------------------
428
        $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...
429
        $criteriaCompo->setOrder($sens);
430
431
        $result = $this->getObjects($criteriaCompo);
432
        $events = $this->objectToArray($result, $externalKeys);
433
        $this->serverTimeToUserTimes($events);
434
435
        return $events;
436
    }
437
438
    /*****************************************************************
439
     * evennement récurents
440
     ****************************************************************
441
     * @param $criteres
442
     * @return array
443
     */
444
445
    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...
446
    {
447
        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...
448
449
        //        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...
450
        foreach ($criteres as $k => $v) {
451
            $$k = $v;
452
        }
453
        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...
454
            $nbDays = 7;
455
        }
456
        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...
457
            $sens = 'ASC';
458
        }
459
        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...
460
            $externalKeys = ['cat_id'];
461
        }
462
        $user = $GLOBALS['xoopsUser'];
463
        //------------------------------------------------------
464
465
        $criteriaCompo =  new \CriteriaCompo();
466
467
        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...
468
            case _EXTCAL_EVENTS_WEEK:
469
            case _EXTCAL_EVENTS_CALENDAR_WEEK:
470
            case _EXTCAL_EVENTS_AGENDA_WEEK:
471 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...
472
                $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...
473
                $end   = userTimeToServerTime(mktime(0, 0, 0, $month, $day + $nbDays + 1, $year), $this->_extcalTime->_getUserTimeZone($user));
474
                //$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...
475
                //$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...
476
                break;
477
478
            case _EXTCAL_EVENTS_MONTH:
479
            case _EXTCAL_EVENTS_CALENDAR_MONTH:
480
                $start = userTimeToServerTime(mktime(0, 0, 0, $month, 1, $year), $this->_extcalTime->_getUserTimeZone($user));
481
                $end   = userTimeToServerTime(mktime(23, 59, 59, $month + 1, 1, $year) - _EXTCAL_TS_DAY, $this->_extcalTime->_getUserTimeZone($user));
482
483
                $criteriaCompo->add( new \Criteria('event_start', $end, '<='));
484
                //$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...
485
486
                break;
487
488 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...
489
                $start = userTimeToServerTime(mktime(0, 0, 0, $month, $day, $year), $this->_extcalTime->_getUserTimeZone($user));
490
                $end   = userTimeToServerTime(mktime(0, 0, 0, $month, $day + 1, $year), $this->_extcalTime->_getUserTimeZone($user));
491
                //$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...
492
493
                break;
494
495
            case _EXTCAL_EVENTS_YEAR:
496
                $start = userTimeToServerTime(mktime(0, 0, 0, 1, 1, $year), $this->_extcalTime->_getUserTimeZone($user));
497
                $end   = userTimeToServerTime(mktime(0, 0, 0, 12, 31, $year), $this->_extcalTime->_getUserTimeZone($user));
498
                break;
499
500
        }
501
        $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...
502
        //--------------------------------------------------------------------------
503
        $criteriaCompo->add( new \Criteria('event_isrecur', 1, '='));
504
        $criteriaCompo->setOrder($sens);
505
506
        $result = $this->getObjects($criteriaCompo);
507
        $events = $this->objectToArray($result, $externalKeys);
508
        $this->serverTimeToUserTimes($events);
509
510
        //Balyage de tous les evennements récurrents et creation de toutes le events
511
        $eventsR = [];
512
        //        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...
513
        foreach ($events as $k => $event) {
514
            //$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...
515
            //$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...
516
            //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...
517
            //ext_echoArray($event);
518
            $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...
519
            if (count($recurEvents) > 0) {
520
                $eventsR = array_merge($eventsR, $recurEvents);
521
            }
522
523
            // Formating date
524
            //$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...
525
        }
526
527
        return $eventsR;
528
    }
529
530
    /*****************************************************************
531
     *
532
     ****************************************************************
533
     * @param        $period
534
     * @param string $caption
535
     */
536
    public function echoDateArray($period, $caption = '')
537
    {
538
        if ('' != $caption) {
539
            echo "<hr>echoDateArray -> {$caption}<br>";
540
        } else {
541
            echo '<hr>echoDateArray<br>';
542
        }
543
544
        reset($period);
545
        foreach ($period as $dt) {
546
            echo $dt->format("l d-m-Y H:i:s\n") . '<br>';
547
        }
548
    }
549
550
    /*****************************************************************
551
     * Criteria
552
     ****************************************************************
553
     * @param     $day
554
     * @param     $month
555
     * @param     $year
556
     * @param int $cat
557
     * @return \CriteriaCompo
558
     */
559
    // Return the criteria compo object for a day
560
    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...
561
    {
562
        $user = $GLOBALS['xoopsUser'];
563
564
        $dayStart      = userTimeToServerTime(mktime(0, 0, 0, $month, $day, $year), $this->_extcalTime->_getUserTimeZone($user));
565
        $dayEnd        = userTimeToServerTime(mktime(23, 59, 59, $month, $day, $year), $this->_extcalTime->_getUserTimeZone($user));
566
        $criteriaCompo = $this->_getListCriteriaCompo($dayStart, $dayEnd, $cat, $user);
567
568
        return $criteriaCompo;
569
    }
570
571
    // Return the criteria compo object for a week
572
573
    /**
574
     * @param     $day
575
     * @param     $month
576
     * @param     $year
577
     * @param     $cat
578
     * @param int $nbDays
579
     *
580
     * @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...
581
     */
582
    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...
583
    {
584
        $user = $GLOBALS['xoopsUser'];
585
586
        $userStartTime = mktime(0, 0, 0, $month, $day, $year);
587
        $userEndTime   = $userStartTime + (_EXTCAL_TS_DAY * $nbDays);
588
        $weekStart     = userTimeToServerTime($userStartTime, $this->_extcalTime->_getUserTimeZone($user));
589
        $weekEnd       = userTimeToServerTime($userEndTime, $this->_extcalTime->_getUserTimeZone($user));
590
        $criteriaCompo = $this->_getCriteriaCompo($weekStart, $weekEnd, $cat, $user);
591
592
        return $criteriaCompo;
593
    }
594
595
    // Return the criteria compo object for a month
596
597
    /**
598
     * @param $month
599
     * @param $year
600
     * @param $cat
601
     *
602
     * @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...
603
     */
604 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...
605
    {
606
        $user = $GLOBALS['xoopsUser'];
607
608
        $userStartTime = mktime(0, 0, 0, $month, 1, $year);
609
        $userEndTime   = mktime(23, 59, 59, $month + 1, 0, $year);
610
        $monthStart    = userTimeToServerTime($userStartTime, $this->_extcalTime->_getUserTimeZone($user));
611
        $monthEnd      = userTimeToServerTime($userEndTime, $this->_extcalTime->_getUserTimeZone($user));
612
        $criteriaCompo = $this->_getCriteriaCompo($monthStart, $monthEnd, $cat, $user);
613
614
        return $criteriaCompo;
615
    }
616
617
    // Return the criteria compo object for event occuring on a given year
618
619
    /**
620
     * @param     $year
621
     * @param int $cat
622
     *
623
     * @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...
624
     */
625 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...
626
    {
627
        $user = $GLOBALS['xoopsUser'];
628
629
        $userStartTime = mktime(0, 0, 0, 1, 1, $year);
630
        $userEndTime   = mktime(23, 59, 59, 12, 31, $year);
631
        $yearStart     = userTimeToServerTime($userStartTime, $this->_extcalTime->_getUserTimeZone($user));
632
        $yearEnd       = userTimeToServerTime($userEndTime, $this->_extcalTime->_getUserTimeZone($user));
633
        $criteriaCompo = $this->_getListCriteriaCompo($yearStart, $yearEnd, $cat, $user);
634
635
        return $criteriaCompo;
636
    }
637
638
    /**********************************************************************
639
     * Debut de - A virer in fine
640
     **********************************************************************/
641
642
    /**********************************************************************
643
     * FIN de  - A virer in fine
644
     **********************************************************************/
645
646
    /**********************************************************************
647
     * Construction des criteres en fonction de la période
648
     *********************************************************************
649
     * @param $start
650
     * @param $end
651
     * @param $cat
652
     * @param $user
653
     * @return \CriteriaCompo
654
     */
655
656
    public function _getCriteriaCompo($start, $end, $cat=0, &$user)
657
    {
658
        $criteriaNoRecur =  new \CriteriaCompo();
659
        $criteriaNoRecur->add( new \Criteria('event_start', $end, '<='));
660
        $criteriaNoRecur->add( new \Criteria('event_end', $start, '>='));
661
        $criteriaNoRecur->add( new \Criteria('event_isrecur', 0));
662
663
        $criteriaRecur =  new \CriteriaCompo();
664
        $criteriaRecur->add( new \Criteria('event_recur_start', $end, '<='));
665
        $criteriaRecur->add( new \Criteria('event_recur_end', $start, '>='));
666
        $criteriaRecur->add( new \Criteria('event_isrecur', 1));
667
668
        $criteriaCompoDate =  new \CriteriaCompo();
669
        $criteriaCompoDate->add($criteriaNoRecur, 'OR');
670
        $criteriaCompoDate->add($criteriaRecur, 'OR');
671
672
        $criteriaCompo =  new \CriteriaCompo();
673
        $criteriaCompo->add($criteriaCompoDate);
674
675
        $criteriaCompo->add( new \Criteria('event_approved', 1));
676
        $this->_addCatSelectCriteria($criteriaCompo, $cat);
677
        $this->_addCatPermCriteria($criteriaCompo, $user);
678
        $criteriaCompo->setSort('event_start');
679
680
        return $criteriaCompo;
681
    }
682
683
    /**
684
     * @param $start
685
     * @param $end
686
     * @param $cat
687
     * @param $user
688
     *
689
     * @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...
690
     */
691 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...
692
    {
693
        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...
694
        $criteriaCompo = $this->_getCriteriaCompo($start, $end, $cat, $user);
695
        //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...
696
        if (!$extcalConfig['diplay_past_event_cal']) {
697
            $criteriaCompo->add( new \Criteria('event_end', time(), '>'));
698
        }
699
700
        return $criteriaCompo;
701
    }
702
703
    /**
704
     * @param $start
705
     * @param $end
706
     * @param $cat
707
     * @param $user
708
     *
709
     * @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...
710
     */
711 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...
712
    {
713
        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...
714
        $criteriaCompo = $this->_getCriteriaCompo($start, $end, $cat, $user);
715
        // 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...
716
        if (!$extcalConfig['diplay_past_event_list']) {
717
            $criteriaCompo->add( new \Criteria('event_end', time(), '>'));
718
        }
719
720
        return $criteriaCompo;
721
    }
722
723
    // Return upcomming event
724
725
    /**
726
     * @param     $nbEvent
727
     * @param int $cat
728
     *
729
     * @return array
730
     */
731
    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...
732
    {
733
        $now = time();
734
735
        $criteriaNoRecur =  new \CriteriaCompo();
736
        $criteriaNoRecur->add( new \Criteria('event_start', $now, '>='));
737
        $criteriaNoRecur->add( new \Criteria('event_isrecur', 0));
738
739
        $criteriaRecur =  new \CriteriaCompo();
740
        $criteriaRecur->add( new \Criteria('event_recur_start', $now, '>='));
741
        $criteriaRecur->add( new \Criteria('event_isrecur', 1));
742
743
        $criteriaCompoDate =  new \CriteriaCompo();
744
        $criteriaCompoDate->add($criteriaNoRecur, 'OR');
745
        $criteriaCompoDate->add($criteriaRecur, 'OR');
746
747
        $criteriaCompo =  new \CriteriaCompo();
748
        $criteriaCompo->add($criteriaCompoDate);
749
750
        $criteriaCompo->add( new \Criteria('event_approved', 1));
751
        $this->_addCatSelectCriteria($criteriaCompo, $cat);
752
        $this->_addCatPermCriteria($criteriaCompo, $GLOBALS['xoopsUser']);
753
754
        //mb ---------- TESTING ---------------------------
755
        //        $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...
756
        //        $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...
757
        //        $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...
758
759
        //var_dump($events);
760
761
        $criteriaCompo->setSort('event_start');
762
        $criteriaCompo->setLimit($nbEvent);
763
764
        //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...
765
        //mb -------------------------------------
766
        return $this->getObjects($criteriaCompo);
767
    }
768
769
    // Return event occuring this day
770
771
    /**
772
     * @param     $nbEvent
773
     * @param int $cat
774
     *
775
     * @return array
776
     */
777
    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...
778
    {
779
        $day   = date('j');
780
        $month = date('n');
781
        $year  = date('Y');
782
783
        $dayStart = mktime(0, 0, 0, $month, $day, $year);
784
        $dayEnd   = mktime(0, 0, 0, $month, $day + 1, $year);
785
786
        $criteriaCompo =  new \CriteriaCompo();
787
        $this->_addCatSelectCriteria($criteriaCompo, $cat);
788
        $this->_addCatPermCriteria($criteriaCompo, $GLOBALS['xoopsUser']);
789
        $criteriaCompo->add( new \Criteria('event_end', $dayStart, '>='));
790
        $criteriaCompo->add( new \Criteria('event_start', $dayEnd, '<'));
791
        $criteriaCompo->add( new \Criteria('event_approved', 1));
792
        $criteriaCompo->setSort('event_start');
793
        $criteriaCompo->setLimit($nbEvent);
794
795
        return $this->getObjects($criteriaCompo);
796
    }
797
798
    // Return last added event
799
800
    /**
801
     * @param      $start
802
     * @param      $limit
803
     * @param int  $cat
804
     * @param bool $skipPerm
805
     *
806
     * @return array
807
     */
808
    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...
809
    {
810
        $criteriaCompo =  new \CriteriaCompo();
811
        $this->_addCatSelectCriteria($criteriaCompo, $cat);
812
        if (!$skipPerm) {
813
            $this->_addCatPermCriteria($criteriaCompo, $GLOBALS['xoopsUser']);
814
        }
815
        $criteriaCompo->add( new \Criteria('event_approved', 1));
816
        $criteriaCompo->setSort('event_id');
817
        $criteriaCompo->setOrder('DESC');
818
        $criteriaCompo->setStart($start);
819
        $criteriaCompo->setLimit($limit);
820
821
        return $this->getObjects($criteriaCompo);
822
    }
823
824
    /**
825
     * @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...
826
     */
827
    public function getCountNewEvent()
828
    {
829
        $criteriaCompo =  new \CriteriaCompo();
830
        $this->_addCatSelectCriteria($criteriaCompo, 0);
831
        $criteriaCompo->add( new \Criteria('event_approved', 1));
832
        $criteriaCompo->setSort('event_id');
833
834
        return $this->getCount($criteriaCompo);
835
    }
836
837
    // Return random upcomming event
838
839
    /**
840
     * @param     $nbEvent
841
     * @param int $cat
842
     *
843
     * @return array
844
     */
845
    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...
846
    {
847
        $criteriaCompo =  new \CriteriaCompo();
848
        $this->_addCatSelectCriteria($criteriaCompo, $cat);
849
        $this->_addCatPermCriteria($criteriaCompo, $GLOBALS['xoopsUser']);
850
        $criteriaCompo->add( new \Criteria('event_start', time(), '>='));
851
        $criteriaCompo->add( new \Criteria('event_approved', 1));
852
        $criteriaCompo->setSort('RAND()');
853
        $criteriaCompo->setLimit($nbEvent);
854
855
        return $this->getObjects($criteriaCompo);
856
    }
857
858
    /**
859
     * @return array
860
     */
861
    public function getPendingEvent()
862
    {
863
        $criteriaCompo =  new \CriteriaCompo();
864
        $criteriaCompo->add( new \Criteria('event_approved', 0));
865
        $criteriaCompo->setSort('event_start');
866
867
        return $this->getObjects($criteriaCompo);
868
    }
869
870
    /**
871
     * @param $criteria
872
     * @param $user
873
     */
874 View Code Duplication
    public function _addCatPermCriteria(&$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...
875
    {
876
        $authorizedAccessCats = $this->_extcalPerm->getAuthorizedCat($user, 'extcal_cat_view');
877
        $count                = count($authorizedAccessCats);
878
        if ($count > 0) {
879
            $in = '(' . $authorizedAccessCats[0];
880
            array_shift($authorizedAccessCats);
881
            foreach ($authorizedAccessCats as $authorizedAccessCat) {
882
                $in .= ',' . $authorizedAccessCat;
883
            }
884
            $in .= ')';
885
            $criteria->add( new \Criteria('cat_id', $in, 'IN'));
886
        } else {
887
            $criteria->add( new \Criteria('cat_id', '(0)', 'IN'));
888
        }
889
    }
890
891
    /**
892
     * @param $criteria
893
     * @param $cats
894
     */
895
    public function _addCatSelectCriteria(&$criteria, $cats=null)
896
    {
897
        if (!is_array($cats) && $cats > 0) {
898
            $criteria->add( new \Criteria('cat_id', $cats));
899
        }
900
        if (is_array($cats)) {
901
            if (false === array_search(0, $cats)) {
902
                $in = '(' . current($cats);
903
                array_shift($cats);
904
                foreach ($cats as $cat) {
905
                    $in .= ',' . $cat;
906
                }
907
                $in .= ')';
908
                $criteria->add( new \Criteria('cat_id', $in, 'IN'));
909
            }
910
        }
911
    }
912
913
    /**********************************************************************
914
     * formulaire d'edition des evennements*
915
     *********************************************************************
916
     * @param string $siteSide
917
     * @param string $mode
918
     * @param null   $data
919
     * @return \ThemeForm|bool
920
     */
921
    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...
922
    {
923
        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...
924
        $catHandler   = Extcal\Helper::getInstance()->getHandler(_EXTCAL_CLN_CAT);
925
        $fileHandler = Extcal\Helper::getInstance()->getHandler(_EXTCAL_CLN_FILE);
926
927
        /***************************************************/
928
//        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...
929
        if ('admin' === $siteSide) {
930
            $action = 'event.php?op=enreg';
931
            $cats   = $catHandler->getAllCat($GLOBALS['xoopsUser'], 'all');
932
        } else {
933
            $action = 'post.php';
934
            $cats   = $catHandler->getAllCat($GLOBALS['xoopsUser']);
935
        }
936
        /***************************************************/
937
        $reccurOptions = [];
938
939
        if ('edit' === $mode || 'clone' === $mode) {
940
            if (!$event = $this->getEventWithNotApprove($data['event_id'])) {
941
                return false;
942
            }
943
            if ('clone' === $mode) {
944
                $data['event_id'] = 0;
945
                $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...
946
                $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...
947
                $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...
948
            }
949
950
            $formTitle           = _MD_EXTCAL_EDIT_EVENT;
951
            $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...
952
            $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...
953
            $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...
954
            $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...
955
            $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...
956
            $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...
957
            $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...
958
            $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...
959
            $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...
960
            $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...
961
            $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...
962
            $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...
963
            $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...
964
            $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...
965
            $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...
966
            $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...
967
            $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...
968
969
            // Configuring recurring form
970
            $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...
971
            $reccurMode   = $eventOptions[0];
972
            array_shift($eventOptions);
973 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...
974
975
                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...
976
977
                    $reccurOptions['rrule_freq']           = 'daily';
978
                    $reccurOptions['rrule_daily_interval'] = $eventOptions[0];
979
980
                    break;
981
982
                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...
983
984
                    $reccurOptions['rrule_freq']            = 'weekly';
985
                    $reccurOptions['rrule_weekly_interval'] = $eventOptions[0];
986
                    array_shift($eventOptions);
987
                    $reccurOptions['rrule_weekly_bydays'] = $eventOptions;
988
989
                    break;
990
991
                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...
992
993
                    $reccurOptions['rrule_freq']             = 'monthly';
994
                    $reccurOptions['rrule_monthly_interval'] = $eventOptions[0];
995
                    array_shift($eventOptions);
996
                    if (0 !== strpos($eventOptions[0], 'MD')) {
997
                        $reccurOptions['rrule_monthly_byday'] = $eventOptions[0];
998
                    } else {
999
                        $reccurOptions['rrule_bymonthday'] = substr($eventOptions[0], 2);
1000
                    }
1001
1002
                    break;
1003
1004
                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...
1005
1006
                    $reccurOptions['rrule_freq']            = 'yearly';
1007
                    $reccurOptions['rrule_yearly_interval'] = $eventOptions[0];
1008
                    array_shift($eventOptions);
1009
                    $reccurOptions['rrule_yearly_byday'] = $eventOptions[0];
1010
                    array_shift($eventOptions);
1011
                    $reccurOptions['rrule_yearly_bymonths'] = $eventOptions;
1012
1013
                    break;
1014
1015
            }
1016
1017
            $files = $fileHandler->objectToArray($fileHandler->getEventFiles($data['event_id']));
1018
            $fileHandler->formatFilesSize($files);
1019
        } elseif ('preview' === $mode) {
1020
            $formTitle           = _MD_EXTCAL_SUBMIT_EVENT;
1021
            $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...
1022
            $title               = $data['event_title'];
1023
            $cat                 = $data['cat_id'];
1024
            $desc                = $data['event_desc'];
1025
            $nbMember            = $data['event_nbmember'];
1026
            $organisateur        = $data['event_organisateur'];
1027
            $contact             = $data['event_contact'];
1028
            $url                 = $data['event_url'];
1029
            $email               = $data['event_email'];
1030
            $event_address       = $data['event_address'];
1031
            $startDateValue      = $data['event_start'];
1032
            $endDateValue        = $data['event_end'];
1033
            $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...
1034
            $event_picture1      = $data['event_picture1'];
1035
            $event_picture2      = $data['event_picture2'];
1036
            $event_price         = $data['event_price'];
1037
            $event_etablissement = $data['event_etablissement'];
1038
            $event_icone         = $data['event_icone'];
1039
1040
            // Configuring recurring form
1041
            $eventOptions = explode('|', $this->getRecurRules($_POST));
1042
            $reccurMode   = $eventOptions[0];
1043
            array_shift($eventOptions);
1044 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...
1045
1046
                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...
1047
1048
                    $reccurOptions['rrule_freq']           = 'daily';
1049
                    $reccurOptions['rrule_daily_interval'] = $eventOptions[0];
1050
1051
                    break;
1052
1053
                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...
1054
1055
                    $reccurOptions['rrule_freq']            = 'weekly';
1056
                    $reccurOptions['rrule_weekly_interval'] = $eventOptions[0];
1057
                    array_shift($eventOptions);
1058
                    $reccurOptions['rrule_weekly_bydays'] = $eventOptions;
1059
1060
                    break;
1061
1062
                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...
1063
1064
                    $reccurOptions['rrule_freq']             = 'monthly';
1065
                    $reccurOptions['rrule_monthly_interval'] = $eventOptions[0];
1066
                    array_shift($eventOptions);
1067
                    if (0 !== strpos($eventOptions[0], 'MD')) {
1068
                        $reccurOptions['rrule_monthly_byday'] = $eventOptions[0];
1069
                    } else {
1070
                        $reccurOptions['rrule_bymonthday'] = substr($eventOptions[0], 2);
1071
                    }
1072
1073
                    break;
1074
1075
                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...
1076
1077
                    $reccurOptions['rrule_freq']            = 'yearly';
1078
                    $reccurOptions['rrule_yearly_interval'] = $eventOptions[0];
1079
                    array_shift($eventOptions);
1080
                    $reccurOptions['rrule_yearly_byday'] = $eventOptions[0];
1081
                    array_shift($eventOptions);
1082
                    $reccurOptions['rrule_yearly_bymonths'] = $eventOptions;
1083
1084
                    break;
1085
1086
            }
1087
1088
            $files = $fileHandler->objectToArray($fileHandler->getEventFiles($data['event_id']));
1089
            $fileHandler->formatFilesSize($files);
1090
        } else {
1091
            $formTitle           = _MD_EXTCAL_SUBMIT_EVENT;
1092
            $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...
1093
            $title               = '';
1094
            $cat                 = '';
1095
            $desc                = '';
1096
            $nbMember            = 0;
1097
            $organisateur        = '';
1098
            $contact             = '';
1099
            $url                 = '';
1100
            $email               = '';
1101
            $event_address       = '';
1102
            $startDateValue      = 0;
1103
            $endDateValue        = 0;
1104
            $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...
1105
            $event_picture1      = '';
1106
            $event_picture2      = '';
1107
            $event_price         = '';
1108
            $event_etablissement = '';
1109
            $files               = [];
1110
            $event_icone         = '';
1111
        }
1112
1113
        // Create XoopsForm Object
1114
        $form = new Extcal\Form\ThemeForm($formTitle, 'event_form', $action, 'post', true);
1115
        // Add this extra to allow file upload
1116
        $form->setExtra('enctype="multipart/form-data"');
1117
1118
        //-----------------------------------------------
1119
        // Title
1120
        $form->addElement( new \XoopsFormText(_MD_EXTCAL_TITLE, 'event_title', 80, 255, $title), true);
1121
        //-----------------------------------------------
1122
        // Category select
1123
        $catSelect = new \XoopsFormSelect(_MD_EXTCAL_CATEGORY, 'cat_id', $cat);
1124
        foreach ($cats as $cat) {
1125
            $catSelect->addOption($cat->getVar('cat_id'), $cat->getVar('cat_name'));
1126
        }
1127
        $form->addElement($catSelect, true);
1128
        //-----------------------------------------------------------
1129
1130
        $file_path = __DIR__ . '/../assets/css/images';
1131
        $tf        = \XoopsLists::getImgListAsArray($file_path);
1132
        array_unshift($tf, _MD_EXTCAL_NONE);
1133
        $xfIcones = new \XoopsFormSelect(_MD_EXTCAL_ICONE, 'event_icone', $event_icone, '');
1134
        $xfIcones->addOptionArray($tf);
1135
        $form->addElement($xfIcones, false);
1136
        //-----------------------------------------------------------
1137
        //etablissement
1138
        $etablissementHandler = Extcal\Helper::getInstance()->getHandler(_EXTCAL_CLN_ETABLISSEMENT);
1139
        $etablissement_select = new \XoopsFormSelect(_MD_EXTCAL_ETABLISSEMENT, 'event_etablissement', $event_etablissement);
1140
        $criteria             =  new \CriteriaCompo();
1141
        $criteria->setSort('nom');
1142
        $criteria->setOrder('ASC');
1143
1144
        //$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...
1145
        $etablissement_arr = $etablissementHandler->getAll($criteria);
1146
        $tEts              = [];
1147
        $tEts[0]           = _MD_EXTCAL_NONE;
1148
        foreach (array_keys($etablissement_arr) as $i) {
1149
            $tEts[$etablissement_arr[$i]->getVar('id')] = $etablissement_arr[$i]->getVar('nom');
1150
            //            $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...
1151
        }
1152
        //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...
1153
1154
        $etablissement_select->addOptionArray($tEts);
1155
        $form->addElement($etablissement_select, true);
1156
1157
        //-----------------------------------------------------------
1158
1159
        // Start and end
1160
        new Extcal\Form\FormDateTime($form, $startDateValue, $endDateValue); //mb
1161
1162
        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...
1163
        $isAdmin = false;
1164
        if (is_object($xoopsUser)) {
1165
            $isAdmin = $xoopsUser->isAdmin($xoopsModule->getVar('mid'));
1166
        }
1167
1168
        // Description
1169 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...
1170
            $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...
1171
            $options['value']  = $desc;
1172
            $options['rows']   = 5;
1173
            $options['cols']   = '100%';
1174
            $options['width']  = '100%';
1175
            $options['height'] = '200px';
1176
            if ($isAdmin) {
1177
                $descEditor = new \XoopsFormEditor(_MD_EXTCAL_DESCRIPTION, $xoopsModuleConfig['editorAdmin'], $options, $nohtml = false, $onfailure = 'textarea');
1178
            } else {
1179
                $descEditor = new \XoopsFormEditor(_MD_EXTCAL_DESCRIPTION, $xoopsModuleConfig['editorUser'], $options, $nohtml = false, $onfailure = 'textarea');
1180
            }
1181
        } else {
1182
            $descEditor = new \XoopsFormDhtmlTextArea(_MD_EXTCAL_DESCRIPTION, 'event_desc', $desc, '100%', '100%');
1183
        }
1184
        $form->addElement($descEditor);
1185
1186
        // Max registered member for this event
1187
        $nbMemberElement = new \XoopsFormText(_MD_EXTCAL_NBMEMBER, 'event_nbmember', 4, 4, $nbMember);
1188
        $nbMemberElement->setDescription(_MD_EXTCAL_NBMEMBER_DESC);
1189
        $form->addElement($nbMemberElement, false);
1190
1191
        //Price and monnaie
1192
        $monnaie_price = new \XoopsFormElementTray(_MD_EXTCAL_PRICE, '');
1193
        //price
1194
        $monnaie_price->addElement( new \XoopsFormText('', 'event_price', 20, 255, $event_price));
1195
        //monnaie
1196
        $monnaie = new \XoopsFormLabel(_MD_EXTCAL_DEVISE2, '');
1197
        $monnaie_price->addElement($monnaie);
1198
        $form->addElement($monnaie_price);
1199
        //----------------------------------------------------------------
1200
        $form->addElement( new \XoopsFormText(_MD_EXTCAL_ORGANISATEUR, 'event_organisateur', 80, 255, $organisateur), false);
1201
        // Contact
1202
        $form->addElement( new \XoopsFormText(_MD_EXTCAL_CONTACT, 'event_contact', 80, 255, $contact), false);
1203
        // Url
1204
        $form->addElement( new \XoopsFormText(_MD_EXTCAL_URL, 'event_url', 80, 255, $url), false);
1205
        // Email
1206
        $form->addElement( new \XoopsFormText(_MD_EXTCAL_EMAIL, 'event_email', 80, 255, $email), false);
1207
1208
        // Address
1209 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...
1210
            $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...
1211
            $options['value']  = $event_address;
1212
            $options['rows']   = 5;
1213
            $options['cols']   = '100%';
1214
            $options['width']  = '100%';
1215
            $options['height'] = '200px';
1216
            if ($isAdmin) {
1217
                $addressEditor = new \XoopsFormEditor(_MD_EXTCAL_DESCRIPTION, $xoopsModuleConfig['editorAdmin'], $options, $nohtml = false, $onfailure = 'textarea');
1218
            } else {
1219
                $addressEditor = new \XoopsFormEditor(_MD_EXTCAL_DESCRIPTION, $xoopsModuleConfig['editorUser'], $options, $nohtml = false, $onfailure = 'textarea');
1220
            }
1221
        } else {
1222
            $addressEditor = new \XoopsFormDhtmlTextArea(_MD_EXTCAL_DESCRIPTION, 'event_address', $event_address, '100%', '100%');
1223
        }
1224
        $form->addElement($addressEditor);
1225
1226
        // Recurence form
1227
        $form->addElement(new Extcal\Form\FormRecurRules($reccurOptions));
1228
        // File attachement
1229
        $fileElmtTray = new \XoopsFormElementTray(_MD_EXTCAL_FILE_ATTACHEMENT, '<br>');
1230
1231
        // If they are attached file to this event
1232
        if (count($files) > 0) {
1233
            $eventFiles = new Extcal\Form\FormFileCheckBox('', 'filetokeep');
1234
            foreach ($files as $file) {
1235
                $name = $file['file_nicename'] . ' (<i>' . $file['file_mimetype'] . '</i>) ' . $file['formated_file_size'];
1236
                $eventFiles->addOption($file['file_id'], $name);
1237
            }
1238
            $fileElmtTray->addElement($eventFiles);
1239
        }
1240
        $fileElmtTray->addElement( new \XoopsFormFile(_MD_EXTCAL_FILE_ATTACHEMENT, 'event_file', 3145728));
1241
        $form->addElement($fileElmtTray);
1242
1243
        if (isset($data['event_id'])) {
1244
            $form->addElement( new \XoopsFormHidden('event_id', $data['event_id']), false);
1245
        }
1246
        //Hack Kraven0
1247
        ///////////////////////////////////////////////////////////////////////////////
1248
        //Picture1
1249
        $file_tray = new \XoopsFormElementTray(sprintf(_MD_EXTCAL_FORM_IMG, 1), '');
1250 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...
1251
            $file_tray->addElement( new \XoopsFormLabel('', "<img src='" . XOOPS_URL . '/uploads/extcal/' . $event_picture1 . "' name='image' id='image' alt=''><br><br>"));
1252
            $check_del_img = new \XoopsFormCheckBox('', 'delimg_1');
1253
            $check_del_img->addOption(1, _MD_EXTCAL_DEL_IMG);
1254
            $file_tray->addElement($check_del_img);
1255
            $file_img = new \XoopsFormFile(_MD_EXTCAL_IMG, 'attachedimage1', 2145728);
1256
            unset($check_del_img);
1257
        } else {
1258
            $file_img = new \XoopsFormFile('', 'attachedimage1', 2145728);
1259
        }
1260
        $file_img->setExtra("size ='40'");
1261
        $file_tray->addElement($file_img);
1262
        $msg        = sprintf(_MD_EXTCAL_IMG_CONFIG, (int)(400728 / 1000), 500, 500);
1263
        $file_label = new \XoopsFormLabel('', '<br>' . $msg);
1264
        $file_tray->addElement($file_label);
1265
        $form->addElement($file_tray);
1266
        $form->addElement( new \XoopsFormHidden('file1', $event_picture1));
1267
        unset($file_img, $file_tray);
1268
        //Picture2
1269
        $file_tray = new \XoopsFormElementTray(sprintf(_MD_EXTCAL_FORM_IMG, 2), '');
1270 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...
1271
            $file_tray->addElement( new \XoopsFormLabel('', "<img src='" . XOOPS_URL . '/uploads/extcal/' . $event_picture2 . "' name='image' id='image' alt=''><br><br>"));
1272
            $check_del_img = new \XoopsFormCheckBox('', 'delimg_2');
1273
            $check_del_img->addOption(1, _MD_EXTCAL_DEL_IMG);
1274
            $file_tray->addElement($check_del_img);
1275
            $file_img = new \XoopsFormFile(_MD_EXTCAL_IMG, 'attachedimage2', 2145728);
1276
            unset($check_del_img);
1277
        } else {
1278
            $file_img = new \XoopsFormFile('', 'attachedimage2', 2145728);
1279
        }
1280
        $file_img->setExtra("size ='40'");
1281
        $file_tray->addElement($file_img);
1282
        $msg        = sprintf(_MD_EXTCAL_IMG_CONFIG, (int)(400728 / 1000), 500, 500);
1283
        $file_label = new \XoopsFormLabel('', '<br>' . $msg);
1284
        $file_tray->addElement($file_label);
1285
        $form->addElement($file_tray);
1286
        $form->addElement( new \XoopsFormHidden('file2', $event_picture2));
1287
        unset($file_img, $file_tray);
1288
        ///////////////////////////////////////////////////////////////////////////////
1289
1290
        $buttonElmtTray = new \XoopsFormElementTray('', '&nbsp;');
1291
        $buttonElmtTray->addElement( new \XoopsFormButton('', 'form_submit', _SUBMIT, 'submit'), false);
1292
        if ('user' === $siteSide) {
1293
            $buttonElmtTray->addElement( new \XoopsFormButton('', 'form_preview', _MD_EXTCAL_PREVIEW, 'submit'), false);
1294
        }
1295
        $form->addElement($buttonElmtTray);
1296
1297
        return $form;
1298
    }
1299
1300
    /********************************************************************/
1301
1302
    /**
1303
     * @param $parm
1304
     *
1305
     * @return bool
1306
     */
1307
    public function getIsRecur($parm)
1308
    {
1309
        $recurFreq = ['daily', 'weekly', 'monthly', 'yearly'];
1310
1311
        return in_array($parm['rrule_freq'], $recurFreq);
1312
    }
1313
1314
    /**
1315
     * @param $parm
1316
     *
1317
     * @return string
1318
     */
1319
    public function getRecurRules($parm)
1320
    {
1321
        //ext_echoArray($parm);exit;
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...
1322
1323
        // If this isn't a reccuring event
1324
        if (!$this->getIsRecur($parm)) {
1325
            return '';
1326
        }
1327
1328
        $recurRules = '';
1329
1330
        $recurFreq = $parm['rrule_freq'];
1331
1332
        switch ($recurFreq) {
1333
1334
            case 'daily':
1335
                if (!isset($parm['rrule_daily_interval'])) {
1336
                    $parm['rrule_daily_interval'] = 0;
1337
                }
1338
                $recurRules = 'daily|';
1339
                $recurRules .= $parm['rrule_daily_interval'];
1340
1341
                break;
1342
1343
            case 'weekly':
1344
                if (!isset($parm['rrule_weekly_interval'])) {
1345
                    $parm['rrule_weekly_interval'] = 0;
1346
                }
1347
                $recurRules = 'weekly|';
1348
                $recurRules .= $parm['rrule_weekly_interval'];
1349
                foreach ($parm['rrule_weekly_bydays'] as $day) {
1350
                    $recurRules .= '|' . $day;
1351
                }
1352
1353
                break;
1354
1355
            case 'monthly':
1356
                if (!isset($parm['rrule_monthly_interval'])) {
1357
                    $parm['rrule_monthly_interval'] = 0;
1358
                }
1359
                $recurRules = 'monthly|';
1360
                $recurRules .= $parm['rrule_monthly_interval'] . '|';
1361
                if ('' != $parm['rrule_monthly_byday']) {
1362
                    $recurRules .= $parm['rrule_monthly_byday'];
1363
                } else {
1364
                    $recurRules .= 'MD' . $parm['rrule_bymonthday'];
1365
                }
1366
1367
                break;
1368
1369
            case 'yearly':
1370
                //JJD - to valid modif
1371
                //
1372
                //                 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...
1373
                //                     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...
1374
                //                     $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...
1375
                //                 }
1376
                //
1377
                //                 $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...
1378
                //                 $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...
1379
                //                 $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...
1380
                //                 foreach (
1381
                //                     $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...
1382
                //) {
1383
                //                     $recurRules .= '|' . $month;
1384
                //                 }
1385
                //
1386
                //                 break;
1387
1388
                if (!isset($parm['rrule_yearly_interval'])) {
1389
                    $parm['rrule_yearly_interval'] = 0;
1390
                }
1391
                if ('' == $parm['rrule_yearly_byday']) {
1392
                    $time                       = strtotime($parm['event_start']['date']);
1393
                    $parm['rrule_yearly_byday'] = date('j', mktime(0, 0, 0, date('m', $time), date('d', $time), date('Y', $time)));
1394
                }
1395
1396
                $recurRules = 'yearly|';
1397
                $recurRules .= $parm['rrule_yearly_interval'];
1398
                $recurRules .= '|' . $parm['rrule_yearly_byday'];
1399
                foreach ($parm['rrule_yearly_bymonths'] as $month) {
1400
                    $recurRules .= '|' . $month;
1401
                }
1402
1403
                break;
1404
1405
        }
1406
1407
        return $recurRules;
1408
    }
1409
1410
    /**
1411
     * @param $data
1412
     * @param $parm
1413
     *
1414
     * @return int
1415
     */
1416
    public function getRecurStart($data, $parm)
1417
    {
1418
1419
        // If this isn't a reccuring event
1420
        if (!$this->getIsRecur($parm)) {
1421
            return 0;
1422
        }
1423
1424
        return $data['event_start'];
1425
    }
1426
1427
    /**
1428
     * @param $data
1429
     * @param $parm
1430
     *
1431
     * @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...
1432
     */
1433
    public function getRecurEnd($data, $parm)
1434
    {
1435
        if (!$this->getIsRecur($parm)) {
1436
            return 0;
1437
        }
1438
1439
        $recurFreq = $parm['rrule_freq'];
1440
1441
        $recurStart = $this->getRecurStart($data, $parm);
1442
1443
        switch ($recurFreq) {
1444
1445
            case 'daily':
1446
                $interval = $parm['rrule_daily_interval'];
1447
                $recurEnd = $recurStart + ($interval * _EXTCAL_TS_DAY) - 1;
1448
1449
                break;
1450
1451
            case 'weekly':
1452
                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...
1453
1454
                // Getting the first weekday TS
1455
                $startWeekTS = mktime(0, 0, 0, date('n', $data['event_recur_start']), date('j', $data['event_recur_start']), date('Y', $data['event_recur_start']));
1456
                $offset      = date('w', $startWeekTS) - $extcalConfig['week_start_day'];
1457
                $startWeekTS -= ($offset * _EXTCAL_TS_DAY);
1458
1459
                $recurEnd = $startWeekTS + ($parm['rrule_weekly_interval'] * _EXTCAL_TS_WEEK) - 1;
1460
1461
                break;
1462
1463
            case 'monthly':
1464
                $recurEnd = $recurStart + ($parm['rrule_monthly_interval'] * 2678400) - 1;
1465
1466
                break;
1467
1468
            case 'yearly':
1469
                $recurEnd = $recurStart + ($parm['rrule_yearly_interval'] * 32140800) - 1;
1470
1471
                break;
1472
1473
        }
1474
1475
        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...
1476
    }
1477
1478
    /*******************************************************************
1479
     *
1480
     ******************************************************************
1481
     * @param $event
1482
     * @param $periodStart
1483
     * @param $periodEnd
1484
     * @return array
1485
     */
1486
    public function getRecurEventToDisplay($event, $periodStart, $periodEnd)
1487
    {
1488
        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...
1489
1490
        $recuEvents   = [];
1491
        $eventOptions = explode('|', $event['event_recur_rules']);
1492
1493
        switch ($eventOptions[0]) {
1494
1495
            case 'daily':
1496
                array_shift($eventOptions);
1497
                $rRuleInterval = $eventOptions[0];
1498
                if ('' == $rRuleInterval || 0 == $rRuleInterval) {
1499
                    $rRuleInterval = 54;
1500
                }
1501
1502
                $occurEventStart = $event['event_recur_start'];
1503
                $occurEventEnd   = $event['event_recur_start'] + ($event['event_end'] - $event['event_start']);
1504
1505
                $nbOccur = 0;
1506
                // This variable is used to stop the loop after we add all occur on the view to keep good performance
1507
                $isOccurOnPeriod = false;
1508
                // Parse all occurence of this event
1509
                while ($nbOccur < $rRuleInterval) {
1510
                    // Add this event occurence only if it's on the period view
1511
                    if // Event start falls within search period
1512
                    ($occurEventStart <= $periodEnd
1513
                     && // Event end falls within search period
1514
                     $occurEventEnd >= $periodStart) {
1515
                        $event['event_start'] = $occurEventStart;
1516
                        $event['event_end']   = $occurEventEnd;
1517
1518
                        $recuEvents[]    = $event;
1519
                        $isOccurOnPeriod = true;
1520
                    } elseif ($isOccurOnPeriod) {
1521
                        break;
1522
                    }
1523
1524
                    $occurEventStart += _EXTCAL_TS_DAY;
1525
                    $occurEventEnd   += _EXTCAL_TS_DAY;
1526
1527
                    ++$nbOccur;
1528
                }
1529
1530
                break;
1531
1532
            case 'weekly':
1533
                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...
1534
1535
                array_shift($eventOptions);
1536
                $rRuleInterval = $eventOptions[0];
1537
                if ('' == $rRuleInterval || 0 == $rRuleInterval) {
1538
                    $rRuleInterval = 54;
1539
                }
1540
                array_shift($eventOptions);
1541
1542
                // Getting the first weekday TS
1543
                $startWeekTS = mktime(0, 0, 0, date('n', $event['event_recur_start']), date('j', $event['event_recur_start']), date('Y', $event['event_recur_start']));
1544
                $offset      = date('w', $startWeekTS) - $extcalConfig['week_start_day'];
1545
                $startWeekTS = $startWeekTS - ($offset * _EXTCAL_TS_DAY) + _EXTCAL_TS_WEEK;
1546
1547
                $occurEventStart = $event['event_recur_start'];
1548
                $occurEventEnd   = $event['event_recur_start'] + ($event['event_end'] - $event['event_start']);
1549
1550
                $dayArray = ['SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'];
1551
1552
                $nbOccur = 0;
1553
1554
                // Parse all occurence of this event
1555
                while ($nbOccur < $rRuleInterval) {
1556
                    // Add this event occurence only if it's on the period view and according to day
1557
                    if ($occurEventStart <= $periodEnd // Event start falls within search period
1558
                        && $occurEventEnd >= $periodStart // Event end falls within search period
1559
                        && in_array($dayArray[date('w', $occurEventStart)], $eventOptions)) {
1560
                        // This week day is selected
1561
1562
                        $event['event_start'] = $occurEventStart;
1563
                        $event['event_end']   = $occurEventEnd;
1564
1565
                        $recuEvents[] = $event;
1566
                    }
1567
1568
                    $occurEventStart += _EXTCAL_TS_DAY;
1569
                    $occurEventEnd   += _EXTCAL_TS_DAY;
1570
1571
                    if ($occurEventStart >= $startWeekTS) {
1572
                        ++$nbOccur;
1573
                        $startWeekTS += _EXTCAL_TS_WEEK;
1574
                    }
1575
                }
1576
1577
                break;
1578
1579
            case 'monthly':
1580
                array_shift($eventOptions);
1581
                $rRuleInterval = $eventOptions[0];
1582
                if ('' == $rRuleInterval || 0 == $rRuleInterval) {
1583
                    $rRuleInterval = 100;
1584
                }
1585
                array_shift($eventOptions);
1586
1587
                $day   = date('j', $event['event_recur_start']);
1588
                $month = date('n', $event['event_recur_start']);
1589
                $year  = date('Y', $event['event_recur_start']);
1590
1591
                $nbOccur = 0;
1592
1593
                $eventHourOccurStart = $event['event_recur_start'] - mktime(0, 0, 0, $month, $day, $year);
1594
                $eventHourOccurEnd   = $event['event_end'] - $event['event_start'];
1595
1596
                // Parse all occurence of this event
1597
                while ($nbOccur < $rRuleInterval) {
1598
                    $eventDayOccurStart = $this->_getOccurTS($month, $year, $eventOptions[0]);
1599
                    if (!$eventDayOccurStart) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $eventDayOccurStart of type integer|null is loosely compared to false; this is ambiguous if the integer can be zero. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
1600
                        $eventDayOccurStart = mktime(0, 0, 0, $month, $day, $year);
1601
                    }
1602
1603
                    $occurEventStart = $eventDayOccurStart + $eventHourOccurStart;
1604
                    $occurEventEnd   = $occurEventStart + $eventHourOccurEnd;
1605
1606 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...
1607
                    ($occurEventStart <= $periodEnd
1608
                     && // Event end falls within search period
1609
                     $occurEventEnd >= $periodStart
1610
                     && // This occur is after start reccur date
1611
                     $occurEventStart >= $event['event_recur_start']) {
1612
                        $event['event_start'] = $occurEventStart;
1613
                        $event['event_end']   = $occurEventEnd;
1614
1615
                        $recuEvents[] = $event;
1616
                    } elseif ($occurEventStart > $periodEnd) {
1617
                        break;
1618
                    }
1619
1620
                    if (13 == ++$month) {
1621
                        $month = 1;
1622
                        ++$year;
1623
                    }
1624
1625
                    ++$nbOccur;
1626
                }
1627
1628
                break;
1629
1630
            case 'yearly':
1631
                array_shift($eventOptions);
1632
                $rRuleInterval = $eventOptions[0];
1633
                if ('' == $rRuleInterval || 0 == $rRuleInterval) {
1634
                    $rRuleInterval = 10;
1635
                }
1636
                array_shift($eventOptions);
1637
                $dayCode = $eventOptions[0];
1638
                array_shift($eventOptions);
1639
1640
                $day   = date('j', $event['event_recur_start']);
1641
                $month = date('n', $event['event_recur_start']);
1642
                $year  = date('Y', $event['event_recur_start']);
1643
1644
                $nbOccur = 0;
1645
1646
                $eventHourOccurStart = $event['event_recur_start'] - mktime(0, 0, 0, $month, $day, $year);
1647
                $eventHourOccurEnd   = $event['event_end'] - $event['event_start'];
1648
1649
                // If recurring month not specified, make it starting month
1650
                if (!count($eventOptions)) {
1651
                    $eventOptions[] = $month;
1652
                }
1653
1654
                // Parse all occurence of this event
1655
                while ($nbOccur < $rRuleInterval) {
1656
                    $eventDayOccurStart = $this->_getOccurTS($month, $year, $dayCode);
1657
                    if (!$eventDayOccurStart) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $eventDayOccurStart of type integer|null is loosely compared to false; this is ambiguous if the integer can be zero. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
1658
                        $eventDayOccurStart = mktime(0, 0, 0, $month, $day, $year);
1659
                    }
1660
1661
                    $occurEventStart = $eventDayOccurStart + $eventHourOccurStart;
1662
                    $occurEventEnd   = $eventDayOccurStart + $eventHourOccurEnd;
1663
1664 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...
1665
                    (($occurEventStart <= $periodEnd)
1666
                     && // Event end falls within search period
1667
                     ($occurEventEnd >= $periodStart)
1668
                     && // This week day is selected
1669
                     in_array($month, $eventOptions)) {
1670
                        $event['event_start'] = $occurEventStart;
1671
                        $event['event_end']   = $occurEventEnd;
1672
1673
                        $recuEvents[] = $event;
1674
                    } elseif ($occurEventStart > $periodEnd) {
1675
                        break;
1676
                    }
1677
1678
                    if (13 == ++$month) {
1679
                        $month = 1;
1680
                        ++$year;
1681
                        ++$nbOccur;
1682
                    }
1683
                }
1684
1685
                break;
1686
1687
        }
1688
1689
        return $recuEvents;
1690
    }
1691
1692
    //-----------------------------------------------------------------
1693
1694
    /**
1695
     * @param $month
1696
     * @param $year
1697
     * @param $dayCode
1698
     *
1699
     * @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...
1700
     */
1701
    public function _getOccurTS($month, $year, $dayCode)
1702
    {
1703
        if (0 === strpos($dayCode, 'MD')) {
1704
            if ('' != substr($dayCode, 2)) {
1705
                return mktime(0, 0, 0, $month, substr($dayCode, 2), $year);
1706
            } else {
1707
                return 0;
1708
            }
1709
        } else {
1710
            switch ($dayCode) {
1711
1712 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...
1713
1714
                    $ts        = mktime(0, 0, 0, $month, 1, $year);
1715
                    $dayOfWeek = date('w', $ts);
1716
                    $ts        = (0 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1717
                    $i         = 0;
1718
                    while (0 != $dayOfWeek % 7) {
1719
                        ++$dayOfWeek;
1720
                        ++$i;
1721
                    }
1722
1723
                    return $ts + (_EXTCAL_TS_DAY * $i);
1724
1725
                    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...
1726
1727 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...
1728
1729
                    $ts        = mktime(0, 0, 0, $month, 1, $year);
1730
                    $dayOfWeek = date('w', $ts);
1731
                    $ts        = (1 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1732
                    $i         = 0;
1733
                    while (1 != $dayOfWeek % 7) {
1734
                        ++$dayOfWeek;
1735
                        ++$i;
1736
                    }
1737
1738
                    return $ts + (_EXTCAL_TS_DAY * $i);
1739
1740
                    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...
1741
1742 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...
1743
1744
                    $ts        = mktime(0, 0, 0, $month, 1, $year);
1745
                    $dayOfWeek = date('w', $ts);
1746
                    $ts        = (2 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1747
                    $i         = 0;
1748
                    while (2 != $dayOfWeek % 7) {
1749
                        ++$dayOfWeek;
1750
                        ++$i;
1751
                    }
1752
1753
                    return $ts + (_EXTCAL_TS_DAY * $i);
1754
1755
                    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...
1756
1757 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...
1758
1759
                    $ts        = mktime(0, 0, 0, $month, 1, $year);
1760
                    $dayOfWeek = date('w', $ts);
1761
                    $ts        = (3 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1762
                    $i         = 0;
1763
                    while (3 != $dayOfWeek % 7) {
1764
                        ++$dayOfWeek;
1765
                        ++$i;
1766
                    }
1767
1768
                    return $ts + (_EXTCAL_TS_DAY * $i);
1769
1770
                    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...
1771
1772 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...
1773
1774
                    $ts        = mktime(0, 0, 0, $month, 1, $year);
1775
                    $dayOfWeek = date('w', $ts);
1776
                    $ts        = (4 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1777
                    $i         = 0;
1778
                    while (4 != $dayOfWeek % 7) {
1779
                        ++$dayOfWeek;
1780
                        ++$i;
1781
                    }
1782
1783
                    return $ts + (_EXTCAL_TS_DAY * $i);
1784
1785
                    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...
1786
1787 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...
1788
1789
                    $ts        = mktime(0, 0, 0, $month, 1, $year);
1790
                    $dayOfWeek = date('w', $ts);
1791
                    $ts        = (5 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1792
                    $i         = 0;
1793
                    while (5 != $dayOfWeek % 7) {
1794
                        ++$dayOfWeek;
1795
                        ++$i;
1796
                    }
1797
1798
                    return $ts + (_EXTCAL_TS_DAY * $i);
1799
1800
                    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...
1801
1802 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...
1803
1804
                    $ts        = mktime(0, 0, 0, $month, 1, $year);
1805
                    $dayOfWeek = date('w', $ts);
1806
                    $ts        = (6 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1807
                    $i         = 0;
1808
                    while (6 != $dayOfWeek % 7) {
1809
                        ++$dayOfWeek;
1810
                        ++$i;
1811
                    }
1812
1813
                    return $ts + (_EXTCAL_TS_DAY * $i);
1814
1815
                    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...
1816
1817 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...
1818
1819
                    $ts        = mktime(0, 0, 0, $month, 7, $year);
1820
                    $dayOfWeek = date('w', $ts);
1821
                    $ts        = (0 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1822
                    $i         = 0;
1823
                    while (0 != $dayOfWeek % 7) {
1824
                        ++$dayOfWeek;
1825
                        ++$i;
1826
                    }
1827
1828
                    return $ts + (_EXTCAL_TS_DAY * $i);
1829
1830
                    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...
1831
1832 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...
1833
1834
                    $ts        = mktime(0, 0, 0, $month, 7, $year);
1835
                    $dayOfWeek = date('w', $ts);
1836
                    $ts        = (1 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1837
                    $i         = 0;
1838
                    while (1 != $dayOfWeek % 7) {
1839
                        ++$dayOfWeek;
1840
                        ++$i;
1841
                    }
1842
1843
                    return $ts + (_EXTCAL_TS_DAY * $i);
1844
1845
                    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...
1846
1847 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...
1848
1849
                    $ts        = mktime(0, 0, 0, $month, 7, $year);
1850
                    $dayOfWeek = date('w', $ts);
1851
                    $ts        = (2 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1852
                    $i         = 0;
1853
                    while (2 != $dayOfWeek % 7) {
1854
                        ++$dayOfWeek;
1855
                        ++$i;
1856
                    }
1857
1858
                    return $ts + (_EXTCAL_TS_DAY * $i);
1859
1860
                    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...
1861
1862 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...
1863
1864
                    $ts        = mktime(0, 0, 0, $month, 7, $year);
1865
                    $dayOfWeek = date('w', $ts);
1866
                    $ts        = (3 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1867
                    $i         = 0;
1868
                    while (3 != $dayOfWeek % 7) {
1869
                        ++$dayOfWeek;
1870
                        ++$i;
1871
                    }
1872
1873
                    return $ts + (_EXTCAL_TS_DAY * $i);
1874
1875
                    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...
1876
1877 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...
1878
1879
                    $ts        = mktime(0, 0, 0, $month, 7, $year);
1880
                    $dayOfWeek = date('w', $ts);
1881
                    $ts        = (4 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1882
                    $i         = 0;
1883
                    while (4 != $dayOfWeek % 7) {
1884
                        ++$dayOfWeek;
1885
                        ++$i;
1886
                    }
1887
1888
                    return $ts + (_EXTCAL_TS_DAY * $i);
1889
1890
                    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...
1891
1892 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...
1893
1894
                    $ts        = mktime(0, 0, 0, $month, 7, $year);
1895
                    $dayOfWeek = date('w', $ts);
1896
                    $ts        = (5 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1897
                    $i         = 0;
1898
                    while (5 != $dayOfWeek % 7) {
1899
                        ++$dayOfWeek;
1900
                        ++$i;
1901
                    }
1902
1903
                    return $ts + (_EXTCAL_TS_DAY * $i);
1904
1905
                    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...
1906
1907 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...
1908
1909
                    $ts        = mktime(0, 0, 0, $month, 7, $year);
1910
                    $dayOfWeek = date('w', $ts);
1911
                    $ts        = (6 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1912
                    $i         = 0;
1913
                    while (6 != $dayOfWeek % 7) {
1914
                        ++$dayOfWeek;
1915
                        ++$i;
1916
                    }
1917
1918
                    return $ts + (_EXTCAL_TS_DAY * $i);
1919
1920
                    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...
1921
1922 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...
1923
1924
                    $ts        = mktime(0, 0, 0, $month, 14, $year);
1925
                    $dayOfWeek = date('w', $ts);
1926
                    $ts        = (0 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1927
                    $i         = 0;
1928
                    while (0 != $dayOfWeek % 7) {
1929
                        ++$dayOfWeek;
1930
                        ++$i;
1931
                    }
1932
1933
                    return $ts + (_EXTCAL_TS_DAY * $i);
1934
1935
                    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...
1936
1937 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...
1938
1939
                    $ts        = mktime(0, 0, 0, $month, 14, $year);
1940
                    $dayOfWeek = date('w', $ts);
1941
                    $ts        = (1 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1942
                    $i         = 0;
1943
                    while (1 != $dayOfWeek % 7) {
1944
                        ++$dayOfWeek;
1945
                        ++$i;
1946
                    }
1947
1948
                    return $ts + (_EXTCAL_TS_DAY * $i);
1949
1950
                    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...
1951
1952 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...
1953
1954
                    $ts        = mktime(0, 0, 0, $month, 14, $year);
1955
                    $dayOfWeek = date('w', $ts);
1956
                    $ts        = (2 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1957
                    $i         = 0;
1958
                    while (2 != $dayOfWeek % 7) {
1959
                        ++$dayOfWeek;
1960
                        ++$i;
1961
                    }
1962
1963
                    return $ts + (_EXTCAL_TS_DAY * $i);
1964
1965
                    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...
1966
1967 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...
1968
1969
                    $ts        = mktime(0, 0, 0, $month, 14, $year);
1970
                    $dayOfWeek = date('w', $ts);
1971
                    $ts        = (3 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1972
                    $i         = 0;
1973
                    while (3 != $dayOfWeek % 7) {
1974
                        ++$dayOfWeek;
1975
                        ++$i;
1976
                    }
1977
1978
                    return $ts + (_EXTCAL_TS_DAY * $i);
1979
1980
                    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...
1981
1982 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...
1983
1984
                    $ts        = mktime(0, 0, 0, $month, 14, $year);
1985
                    $dayOfWeek = date('w', $ts);
1986
                    $ts        = (4 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1987
                    $i         = 0;
1988
                    while (4 != $dayOfWeek % 7) {
1989
                        ++$dayOfWeek;
1990
                        ++$i;
1991
                    }
1992
1993
                    return $ts + (_EXTCAL_TS_DAY * $i);
1994
1995
                    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...
1996
1997 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...
1998
1999
                    $ts        = mktime(0, 0, 0, $month, 14, $year);
2000
                    $dayOfWeek = date('w', $ts);
2001
                    $ts        = (5 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
2002
                    $i         = 0;
2003
                    while (5 != $dayOfWeek % 7) {
2004
                        ++$dayOfWeek;
2005
                        ++$i;
2006
                    }
2007
2008
                    return $ts + (_EXTCAL_TS_DAY * $i);
2009
2010
                    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...
2011
2012 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...
2013
2014
                    $ts        = mktime(0, 0, 0, $month, 14, $year);
2015
                    $dayOfWeek = date('w', $ts);
2016
                    $ts        = (6 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
2017
                    $i         = 0;
2018
                    while (6 != $dayOfWeek % 7) {
2019
                        ++$dayOfWeek;
2020
                        ++$i;
2021
                    }
2022
2023
                    return $ts + (_EXTCAL_TS_DAY * $i);
2024
2025
                    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...
2026
2027 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...
2028
2029
                    $ts        = mktime(0, 0, 0, $month, 21, $year);
2030
                    $dayOfWeek = date('w', $ts);
2031
                    $ts        = (0 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
2032
                    $i         = 0;
2033
                    while (0 != $dayOfWeek % 7) {
2034
                        ++$dayOfWeek;
2035
                        ++$i;
2036
                    }
2037
2038
                    return $ts + (_EXTCAL_TS_DAY * $i);
2039
2040
                    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...
2041
2042 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...
2043
2044
                    $ts        = mktime(0, 0, 0, $month, 21, $year);
2045
                    $dayOfWeek = date('w', $ts);
2046
                    $ts        = (1 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
2047
                    $i         = 0;
2048
                    while (1 != $dayOfWeek % 7) {
2049
                        ++$dayOfWeek;
2050
                        ++$i;
2051
                    }
2052
2053
                    return $ts + (_EXTCAL_TS_DAY * $i);
2054
2055
                    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...
2056
2057 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...
2058
2059
                    $ts        = mktime(0, 0, 0, $month, 21, $year);
2060
                    $dayOfWeek = date('w', $ts);
2061
                    $ts        = (2 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
2062
                    $i         = 0;
2063
                    while (2 != $dayOfWeek % 7) {
2064
                        ++$dayOfWeek;
2065
                        ++$i;
2066
                    }
2067
2068
                    return $ts + (_EXTCAL_TS_DAY * $i);
2069
2070
                    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...
2071
2072 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...
2073
2074
                    $ts        = mktime(0, 0, 0, $month, 21, $year);
2075
                    $dayOfWeek = date('w', $ts);
2076
                    $ts        = (3 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
2077
                    $i         = 0;
2078
                    while (3 != $dayOfWeek % 7) {
2079
                        ++$dayOfWeek;
2080
                        ++$i;
2081
                    }
2082
2083
                    return $ts + (_EXTCAL_TS_DAY * $i);
2084
2085
                    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...
2086
2087 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...
2088
2089
                    $ts        = mktime(0, 0, 0, $month, 21, $year);
2090
                    $dayOfWeek = date('w', $ts);
2091
                    $ts        = (4 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
2092
                    $i         = 0;
2093
                    while (4 != $dayOfWeek % 7) {
2094
                        ++$dayOfWeek;
2095
                        ++$i;
2096
                    }
2097
2098
                    return $ts + (_EXTCAL_TS_DAY * $i);
2099
2100
                    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...
2101
2102 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...
2103
2104
                    $ts        = mktime(0, 0, 0, $month, 21, $year);
2105
                    $dayOfWeek = date('w', $ts);
2106
                    $ts        = (5 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
2107
                    $i         = 0;
2108
                    while (5 != $dayOfWeek % 7) {
2109
                        ++$dayOfWeek;
2110
                        ++$i;
2111
                    }
2112
2113
                    return $ts + (_EXTCAL_TS_DAY * $i);
2114
2115
                    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...
2116
2117 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...
2118
2119
                    $ts        = mktime(0, 0, 0, $month, 21, $year);
2120
                    $dayOfWeek = date('w', $ts);
2121
                    $ts        = (6 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
2122
                    $i         = 0;
2123
                    while (6 != $dayOfWeek % 7) {
2124
                        ++$dayOfWeek;
2125
                        ++$i;
2126
                    }
2127
2128
                    return $ts + (_EXTCAL_TS_DAY * $i);
2129
2130
                    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...
2131
2132 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...
2133
2134
                    $ts        = mktime(0, 0, 0, $month, date('t', mktime(0, 0, 0, $month, 1, $year)), $year);
2135
                    $dayOfWeek = date('w', $ts);
2136
                    $i         = 0;
2137
                    while (0 != $dayOfWeek % 7) {
2138
                        ++$dayOfWeek;
2139
                        ++$i;
2140
                    }
2141
                    if (0 == $i) {
2142
                        return $ts;
2143
                    }
2144
2145
                    return $ts + (_EXTCAL_TS_DAY * ($i - 7));
2146
2147
                    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...
2148
2149 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...
2150
2151
                    $ts        = mktime(0, 0, 0, $month, date('t', mktime(0, 0, 0, $month, 1, $year)), $year);
2152
                    $dayOfWeek = date('w', $ts);
2153
                    $i         = 0;
2154
                    while (1 != $dayOfWeek % 7) {
2155
                        ++$dayOfWeek;
2156
                        ++$i;
2157
                    }
2158
                    if (0 == $i) {
2159
                        return $ts;
2160
                    }
2161
2162
                    return $ts + (_EXTCAL_TS_DAY * ($i - 7));
2163
2164
                    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...
2165
2166 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...
2167
2168
                    $ts        = mktime(0, 0, 0, $month, date('t', mktime(0, 0, 0, $month, 1, $year)), $year);
2169
                    $dayOfWeek = date('w', $ts);
2170
                    $i         = 0;
2171
                    while (2 != $dayOfWeek % 7) {
2172
                        ++$dayOfWeek;
2173
                        ++$i;
2174
                    }
2175
                    if (0 == $i) {
2176
                        return $ts;
2177
                    }
2178
2179
                    return $ts + (_EXTCAL_TS_DAY * ($i - 7));
2180
2181
                    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...
2182
2183 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...
2184
2185
                    $ts        = mktime(0, 0, 0, $month, date('t', mktime(0, 0, 0, $month, 1, $year)), $year);
2186
                    $dayOfWeek = date('w', $ts);
2187
                    $i         = 0;
2188
                    while (3 != $dayOfWeek % 7) {
2189
                        ++$dayOfWeek;
2190
                        ++$i;
2191
                    }
2192
                    if (0 == $i) {
2193
                        return $ts;
2194
                    }
2195
2196
                    return $ts + (_EXTCAL_TS_DAY * ($i - 7));
2197
2198
                    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...
2199
2200 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...
2201
2202
                    $ts        = mktime(0, 0, 0, $month, date('t', mktime(0, 0, 0, $month, 1, $year)), $year);
2203
                    $dayOfWeek = date('w', $ts);
2204
                    $i         = 0;
2205
                    while (4 != $dayOfWeek % 7) {
2206
                        ++$dayOfWeek;
2207
                        ++$i;
2208
                    }
2209
                    if (0 == $i) {
2210
                        return $ts;
2211
                    }
2212
2213
                    return $ts + (_EXTCAL_TS_DAY * ($i - 7));
2214
2215
                    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...
2216
2217 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...
2218
2219
                    $ts        = mktime(0, 0, 0, $month, date('t', mktime(0, 0, 0, $month, 1, $year)), $year);
2220
                    $dayOfWeek = date('w', $ts);
2221
                    $i         = 0;
2222
                    while (5 != $dayOfWeek % 7) {
2223
                        ++$dayOfWeek;
2224
                        ++$i;
2225
                    }
2226
                    if (0 == $i) {
2227
                        return $ts;
2228
                    }
2229
2230
                    return $ts + (_EXTCAL_TS_DAY * ($i - 7));
2231
2232
                    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...
2233
2234 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...
2235
2236
                    $ts        = mktime(0, 0, 0, $month, date('t', mktime(0, 0, 0, $month, 1, $year)), $year);
2237
                    $dayOfWeek = date('w', $ts);
2238
                    $i         = 0;
2239
                    while (6 != $dayOfWeek % 7) {
2240
                        ++$dayOfWeek;
2241
                        ++$i;
2242
                    }
2243
                    if (0 == $i) {
2244
                        return $ts;
2245
                    }
2246
2247
                    return $ts + (_EXTCAL_TS_DAY * ($i - 7));
2248
2249
                    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...
2250
2251
                default:
2252
                    return 0;
2253
2254
                    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...
2255
2256
            }
2257
        }
2258
    }
2259
2260
    /*************************************************************************
2261
     *
2262
     ************************************************************************
2263
     * @param $year
2264
     * @param $month
2265
     * @param $day
2266
     * @param $cat
2267
     * @param $searchExp
2268
     * @param $andor
2269
     * @param $orderBy
2270
     * @return array
2271
     */
2272
    public function getSearchEvent2($year, $month, $day, $cat, $searchExp, $andor, $orderBy)
2273
    {
2274
        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...
2275
2276
        if (isset($xoopsUser)) {
2277
            $userId = $xoopsUser->getVar('uid');
2278
            $result = $this->getSearchEvents($year, $month, $day, $cat, $searchExp, $andor, $orderBy, 0, 0, $userId, $xoopsUser);
2279
        } else {
2280
            $result = $this->getSearchEvents($year, $month, $day, $cat, $searchExp, $andor, $orderBy, 0, 0);
2281
        }
2282
2283
        $ret = [];
2284
        while ($myrow = $xoopsDB->fetchArray($result)) {
2285
            $myrow['cat']['cat_name']        = $myrow['cat_name'];
2286
            $myrow['cat']['cat_color']       = $myrow['cat_color'];
2287
            $myrow['cat']['cat_light_color'] = Extcal\Utility::getLighterColor($myrow['cat']['cat_color'], _EXTCAL_INFOBULLE_RGB_MIN, _EXTCAL_INFOBULLE_RGB_MAX);
2288
            if ('' == $myrow['event_icone']) {
2289
                $myrow['event_icone'] = $myrow['cat']['cat_icone'];
2290
            }
2291
            $ret[] = $myrow;
2292
        }
2293
2294
        return $ret;
2295
    }
2296
2297
    //-----------------------------------------------------------
2298
2299
    /**
2300
     * @param int    $year
2301
     * @param int    $month
2302
     * @param int    $day
2303
     * @param int    $cat
2304
     * @param        $queryarray
2305
     * @param        $andor
2306
     * @param        $orderBy
2307
     * @param int    $limit
2308
     * @param int    $offset
2309
     * @param int    $userId
2310
     * @param string $user
2311
     *
2312
     * @return mixed
2313
     */
2314
    public function getSearchEvents(
2315
        $year = 0,
2316
        $month = 0,
2317
        $day = 0,
2318
        $cat = 0,
2319
        $queryarray,
2320
        $andor,
2321
        $orderBy,
2322
        $limit = 0,
2323
        $offset = 0,
2324
        $userId = 0,
2325
        $user = ''
2326
    ) {
2327
        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...
2328
2329
        //echo "<hr>{$andor}-{$limit}-{$offset}-{$userId}-{$user}<br>{$criteresPlus}";
2330
        $tEvent = $xoopsDB->prefix('extcal_event') . ' AS te';
2331
        $tCat   = $xoopsDB->prefix('extcal_cat') . ' AS tc';
2332
2333
        $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}";
2334
        //---------------------------------------------------
2335
        $tw   = [];
2336
        $tw[] = 'te.cat_id = tc.cat_id';
2337
        $tw[] = 'event_approved = 1';
2338
2339
        $authorizedAccessCats = $this->_extcalPerm->getAuthorizedCat($user, 'extcal_cat_view');
2340
        $inCat                = 'te.cat_id IN (0)';
2341
        if (count($authorizedAccessCats) > 0) {
2342
            $inCat = 'te.cat_id IN (' . implode(',', $authorizedAccessCats) . ')';
2343
        }
2344
        //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...
2345
2346
        if (0 != $userId) {
2347
            $tw[] .= "({$inCat} OR event_submitter = {$userId} )";
2348
        } else {
2349
            $tw[] = $inCat;
2350
        }
2351
        //--------------------------------------------------------
2352
        if ($cat > 0) {
2353
            $tw[] .= "te.cat_id = {$cat}";
2354
        }
2355
        if ($year > 0) {
2356
            $tw[] .= "year(FROM_UNIXTIME(event_start)) = {$year}";
2357
        }
2358
        if ($month > 0) {
2359
            $tw[] .= "month(FROM_UNIXTIME(event_start)) = {$month}";
2360
        }
2361
        if ($day > 0) {
2362
            $tw[] .= "day(FROM_UNIXTIME(event_start)) = {$day}";
2363
        }
2364
2365
        //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...
2366
        if (!is_array($queryarray)) {
2367
            $queryarray = (('' != $queryarray) ? explode(' ', $queryarray) : '');
2368
        }
2369
2370
        if (is_array($queryarray)) {
2371
            $tFields = [
2372
                'te.event_title',
2373
                'te.event_desc',
2374
                'te.event_contact',
2375
                'te.event_address',
2376
                'tc.cat_name',
2377
            ];
2378
            $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...
2379 View Code Duplication
            for ($i = 0, $count = count($queryarray); $i < $count; ++$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...
2380
                $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...
2381
            }
2382
2383
            $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...
2384
2385
            $t = [];
2386 View Code Duplication
            for ($h = 0, $count = count($tFields); $h < $count; ++$h) {
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...
2387
                $t[] = sprintf($flt, $tFields[$h]);
2388
            }
2389
2390
            $filtre = implode(' OR ', $t);
2391
            $filtre = str_replace('#', '%', $filtre);
2392
            $tw[]   = '(' . $filtre . ')';
2393
        }
2394
2395
        $sql .= ' WHERE ' . implode(' AND ', $tw);
2396
        //------------------------------------------------------------
2397
        if (count($orderBy) > 0) {
2398
            $t = [];
2399 View Code Duplication
            for ($h = 0, $count = count($orderBy); $h < $count; ++$h) {
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...
2400
                if ('' != $orderBy[$h]) {
2401
                    $t[] = $orderBy[$h];
2402
                }
2403
            }
2404
            if (count($t) > 0) {
2405
                $sql .= ' ORDER BY ' . implode(',', $t);
2406
            }
2407
        }
2408
2409
        //----------------------------------------------------------------
2410
2411
        $result = $xoopsDB->query($sql, $limit, $offset);
2412
2413
        // echo "<hr>{$sql}<hr>";
2414
        return $result;
2415
    }
2416
2417
    //-----------------------------------------------------------
2418
2419
    /**
2420
     * @param $queryarray
2421
     * @param $andor
2422
     * @param $limit
2423
     * @param $offset
2424
     * @param $userId
2425
     * @param $user
2426
     *
2427
     * @return mixed
2428
     */
2429
    public function getSearchEvent($queryarray, $andor, $limit, $offset, $userId, $user)
2430
    {
2431
        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...
2432
2433
        $result = $this->getSearchEvents(0, 0, 0, 0, $queryarray, $andor, ['event_id DESC']);
2434
2435
        $i = 0;
2436 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...
2437
            $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...
2438
            $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...
2439
            $ret[$i]['title'] = $myrow['event_title'];
2440
            $ret[$i]['time']  = $myrow['event_submitdate'];
2441
            $ret[$i]['uid']   = $myrow['event_submitter'];
2442
            ++$i;
2443
        }
2444
2445
        return $ret;
2446
    }
2447
2448
    /**
2449
     * @param        $queryarray
2450
     * @param        $andor
2451
     * @param        $limit
2452
     * @param        $offset
2453
     * @param        $userId
2454
     * @param        $user
2455
     * @param string $criteresPlus
2456
     * @param bool   $xoopsSearch
2457
     *
2458
     * @return array
2459
     */
2460
    public function getSearchEvent3(
2461
        $queryarray,
2462
        $andor,
2463
        $limit,
2464
        $offset,
2465
        $userId,
2466
        $user,
2467
        $criteresPlus = '',
2468
        $xoopsSearch = true
2469
    ) {
2470
        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...
2471
        //echo "<hr>{$andor}-{$limit}-{$offset}-{$userId}-{$user}<br>{$criteresPlus}";
2472
2473
        //        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...
2474
        //            $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...
2475
        //        }
2476
        $tEvent = $xoopsDB->prefix('extcal_event');
2477
        $tCat   = $xoopsDB->prefix('extcal_cat');
2478
        $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'";
2479
2480
        $authorizedAccessCats = $this->_extcalPerm->getAuthorizedCat($user, 'extcal_cat_view');
2481
        $count                = count($authorizedAccessCats);
2482
        if ($count > 0) {
2483
            $in = '(' . $authorizedAccessCats[0];
2484
            array_shift($authorizedAccessCats);
2485
            foreach ($authorizedAccessCats as $authorizedAccessCat) {
2486
                $in .= ',' . $authorizedAccessCat;
2487
            }
2488
            $in .= ')';
2489
        } else {
2490
            $in = '(0)';
2491
        }
2492
        $sql .= " AND {$tEvent}.cat_id IN " . $in . '';
2493
        if (0 != $userId) {
2494
            $sql .= " AND event_submitter = '" . $userId . "'";
2495
        }
2496
2497
        //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...
2498
        if (is_array($queryarray)) {
2499
            /*
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...
2500
            $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]%')";
2501
            for ($i = 1; $i < $count; ++$i) {
2502
                $sql .= " $andor ";
2503
                $sql .= "(event_title LIKE '%$queryarray[0]%' OR event_desc LIKE '%$queryarray[0]%' OR event_contact LIKE '%$queryarray[0]%' OR event_address LIKE '%$queryarray[0]%')";
2504
            }
2505
            $sql .= ") ";
2506
            */
2507
2508
            $tFields = ['event_title', 'event_desc', 'event_contact', 'event_address', 'cat_name'];
2509
            $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...
2510 View Code Duplication
            for ($i = 0, $count = count($queryarray); $i < $count; ++$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...
2511
                $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...
2512
            }
2513
2514
            $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...
2515
2516
            $t = [];
2517 View Code Duplication
            for ($h = 0, $count = count($tFields); $h < $count; ++$h) {
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...
2518
                $t[] = sprintf($flt, $tFields[$h]);
2519
            }
2520
2521
            $filtre = implode(' OR ', $t);
2522
            $filtre = str_replace('#', '%', $filtre);
2523
            $sql    .= " AND ($filtre)";
2524
        }
2525
2526
        if ('' != $criteresPlus) {
2527
            $sql .= ' AND ' . $criteresPlus;
2528
        }
2529
        $sql .= ' ORDER BY event_id DESC';
2530
2531
        $result = $xoopsDB->query($sql, $limit, $offset);
2532
        $ret    = [];
2533
        $i      = 0;
2534
        if ($xoopsSearch) {
2535 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...
2536
                $ret[$i]['image'] = 'assets/images/icons/extcal.gif';
2537
                $ret[$i]['link']  = 'event.php?event=' . $myrow['event_id'];
2538
                $ret[$i]['title'] = $myrow['event_title'];
2539
                $ret[$i]['time']  = $myrow['event_submitdate'];
2540
                $ret[$i]['uid']   = $myrow['event_submitter'];
2541
                ++$i;
2542
            }
2543
        } else {
2544
            while ($myrow = $xoopsDB->fetchArray($result)) {
2545
                $myrow['cat']['cat_name']  = $myrow['cat_name'];
2546
                $myrow['cat']['cat_color'] = $myrow['cat_color'];
2547
                $ret[]                     = $myrow;
2548
                ++$i;
2549
            }
2550
        }
2551
2552
        return $ret;
2553
    }
2554
2555
    /**
2556
     * @param $event
2557
     * @param $eventsArray
2558
     * @param $startPeriod
2559
     * @param $endPeriod
2560
     */
2561
    public function addEventToCalArray(&$event, &$eventsArray, $startPeriod, $endPeriod)
2562
    {
2563
        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...
2564
2565
        // Calculating the start and the end of the event
2566
        $startEvent = $event['event_start'];
2567
        $endEvent   = $event['event_end'];
2568
2569
        // This event start before this month and finish after
2570
        if ($startEvent < $startPeriod && $endEvent > $endPeriod) {
2571
            $endFor = date('t', mktime(0, 0, 0, $month, 1, $year));
2572
            for ($i = 1; $i <= $endFor; ++$i) {
2573
                $event['status']   = 'middle';
2574
                $eventsArray[$i][] = $event;
2575
            }
2576
            // This event start before this month and finish during
2577
        } else {
2578
            if ($startEvent < $startPeriod) {
2579
                $endFor = date('j', $endEvent);
2580 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...
2581
                    $event['status']   = ($i != $endFor) ? 'middle' : 'end';
2582
                    $eventsArray[$i][] = $event;
2583
                }
2584
                // This event start during this month and finish after
2585
            } else {
2586
                if ($endEvent > $endPeriod) {
2587
                    $startFor = date('j', $startEvent);
2588
                    $endFor   = date('t', mktime(0, 0, 0, $month, 1, $year));
2589 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...
2590
                        $event['status']   = ($i == $startFor) ? 'start' : 'middle';
2591
                        $eventsArray[$i][] = $event;
2592
                    }
2593
                    // This event start and finish during this month
2594
                } else {
2595
                    $startFor = date('j', $startEvent);
2596
                    $endFor   = date('j', $endEvent);
2597
                    for ($i = $startFor; $i <= $endFor; ++$i) {
2598
                        if ($startFor == $endFor) {
2599
                            $event['status'] = 'single';
2600
                        } else {
2601
                            if ($i == $startFor) {
2602
                                $event['status'] = 'start';
2603
                            } else {
2604
                                if ($i == $endFor) {
2605
                                    $event['status'] = 'end';
2606
                                } else {
2607
                                    $event['status'] = 'middle';
2608
                                }
2609
                            }
2610
                        }
2611
                        $eventsArray[$i][] = $event;
2612
                    }
2613
                }
2614
            }
2615
        }
2616
    }
2617
2618
    //-------------------------------------------------
2619
} // -------- Fin e la classe ---------------------
2620