Passed
Pull Request — master (#2)
by tsms
01:30
created

Calendar   B

Complexity

Total Complexity 48

Size/Duplication

Total Lines 658
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 156
dl 0
loc 658
rs 8.5599
c 0
b 0
f 0
wmc 48

36 Methods

Rating   Name   Duplication   Size   Complexity  
A thisDay() 0 5 1
A nextYear() 0 4 1
A build() 0 6 1
A isToday() 0 3 1
A defineFirstDayOfWeek() 0 19 5
A nextHour() 0 5 1
A size() 0 3 1
A nextSecond() 0 6 1
A returnValue() 0 16 5
A getEngine() 0 3 1
A fetchAll() 0 3 1
A toArray() 0 12 2
A adjust() 0 9 1
A nextDay() 0 5 1
A getValidator() 0 7 2
A prevSecond() 0 6 1
A prevMinute() 0 6 1
A thisMinute() 0 6 1
A nextMonth() 0 4 1
A prevDay() 0 5 1
A isValid() 0 4 1
A prevYear() 0 4 1
A getTimestamp() 0 5 1
A prevHour() 0 5 1
A thisYear() 0 4 1
A setSelection() 0 7 1
A fetch() 0 8 2
A thisMonth() 0 4 1
A isSelected() 0 3 1
A nextMinute() 0 6 1
A prevMonth() 0 4 1
A __construct() 0 13 2
A thisHour() 0 5 1
A setSelected() 0 3 1
A setTimestamp() 0 8 1
A thisSecond() 0 6 1

How to fix   Complexity   

Complex Class

Complex classes like Calendar often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Calendar, and based on these observations, apply Extract Interface, too.

1
<?php
2
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
3
4
/**
5
 * Contains the Calendar and Calendar_Engine_Factory classes
6
 *
7
 * PHP versions 4 and 5
8
 *
9
 * LICENSE: Redistribution and use in source and binary forms, with or without
10
 * modification, are permitted provided that the following conditions are met:
11
 * 1. Redistributions of source code must retain the above copyright
12
 *    notice, this list of conditions and the following disclaimer.
13
 * 2. Redistributions in binary form must reproduce the above copyright
14
 *    notice, this list of conditions and the following disclaimer in the
15
 *    documentation and/or other materials provided with the distribution.
16
 * 3. The name of the author may not be used to endorse or promote products
17
 *    derived from this software without specific prior written permission.
18
 *
19
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
20
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22
 * IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
23
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
 *
30
 * @category  Date and Time
31
 * @package   Calendar
32
 * @author    Harry Fuecks <[email protected]>
33
 * @author    Lorenzo Alberton <[email protected]>
34
 * @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
35
 * @license   http://www.debian.org/misc/bsd.license  BSD License (3 Clause)
36
 * @version   CVS: $Id$
37
 * @link      http://pear.php.net/package/Calendar
38
 */
39
namespace PEAR\Calendar;
40
41
/**
42
 * Allows Calendar include path to be redefined
43
 */
44
if (!defined('CALENDAR_ROOT')) {
45
    define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
46
}
47
48
/**
49
 * Constant which defines the calculation engine to use
50
 */
51
if (!defined('CALENDAR_ENGINE')) {
52
    define('CALENDAR_ENGINE', 'UnixTS');
53
}
54
55
/**
56
 * Define Calendar Month states
57
 */
58
define('CALENDAR_USE_MONTH',          1);
59
define('CALENDAR_USE_MONTH_WEEKDAYS', 2);
60
define('CALENDAR_USE_MONTH_WEEKS',    3);
61
62
/**
63
 * Contains a factory method to return a Singleton instance of a class
64
 * implementing the Calendar_Engine_Interface.<br>
65
 * <b>Note:</b> this class must be modified to "register" alternative
66
 * Calendar_Engines. The engine used can be controlled with the constant
67
 * CALENDAR_ENGINE
68
 *
69
 * @category  Date and Time
70
 * @package   Calendar
71
 * @author    Harry Fuecks <[email protected]>
72
 * @author    Lorenzo Alberton <[email protected]>
73
 * @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
74
 * @license   http://www.debian.org/misc/bsd.license  BSD License (3 Clause)
75
 * @link      http://pear.php.net/package/Calendar
76
 * @see       CalendarEngineInterface
77
 * @access    protected
78
 */
79
class Calendar_Engine_Factory
80
{
81
    /**
82
     * Returns an instance of the engine
83
     *
84
     * @return object instance of a calendar calculation engine
85
     * @access public
86
     */
87
    static public function & getEngine()
88
    {
89
        static $engine = false;
90
        switch (CALENDAR_ENGINE) {
91
        case 'PearDate':
92
            $class = 'Calendar_Engine_PearDate';
93
            break;
94
        case 'UnixTS':
95
        default:
96
            $class = 'PEAR\Calendar\Engine\UnixTS';
97
            break;
98
        }
99
        if (!$engine) {
100
            if (!class_exists($class)) {
101
                include_once CALENDAR_ROOT.'Engine'.DIRECTORY_SEPARATOR.CALENDAR_ENGINE.'.php';
102
            }
103
            $engine = new $class;
104
        }
105
        return $engine;
106
    }
107
}
108
109
/**
110
 * Base class for Calendar API. This class should not be instantiated directly.
111
 *
112
 * @category  Date and Time
113
 * @package   Calendar
114
 * @author    Harry Fuecks <[email protected]>
115
 * @author    Lorenzo Alberton <[email protected]>
116
 * @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
117
 * @license   http://www.debian.org/misc/bsd.license  BSD License (3 Clause)
118
 * @link      http://pear.php.net/package/Calendar
119
 * @abstract
120
 */
121
class Calendar
122
{
123
    /**
124
     * Instance of class implementing calendar engine interface
125
     * @var object
126
     * @access private
127
     */
128
    var $cE;
129
130
    /**
131
     * Instance of Calendar_Validator (lazy initialized when isValid() or
132
     * getValidor() is called
133
     * @var Validator
134
     * @access private
135
     */
136
    var $validator;
137
138
    /**
139
     * Year for this calendar object e.g. 2003
140
     * @access private
141
     * @var int
142
     */
143
    var $year;
144
145
    /**
146
     * Month for this calendar object e.g. 9
147
     * @access private
148
     * @var int
149
     */
150
    var $month;
151
152
    /**
153
     * Day of month for this calendar object e.g. 23
154
     * @access private
155
     * @var int
156
     */
157
    var $day;
158
159
    /**
160
     * Hour of day for this calendar object e.g. 13
161
     * @access private
162
     * @var int
163
     */
164
    var $hour;
165
166
    /**
167
     * Minute of hour this calendar object e.g. 46
168
     * @access private
169
     * @var int
170
     */
171
    var $minute;
172
173
    /**
174
     * Second of minute this calendar object e.g. 34
175
     * @access private
176
     * @var int
177
     */
178
    var $second;
179
180
    /**
181
     * Marks this calendar object as selected (e.g. 'today')
182
     * @access private
183
     * @var boolean
184
     */
185
    var $selected = false;
186
187
    /**
188
     * Collection of child calendar objects created from subclasses
189
     * of Calendar. Type depends on the object which created them.
190
     * @access private
191
     * @var array
192
     */
193
    var $children = array();
194
195
    /**
196
     * Constructs the Calendar
197
     *
198
     * @param int $y year
199
     * @param int $m month
200
     * @param int $d day
201
     * @param int $h hour
202
     * @param int $i minute
203
     * @param int $s second
204
     *
205
     * @access protected
206
     */
207
    function __construct($y = 2000, $m = 1, $d = 1, $h = 0, $i = 0, $s = 0)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
208
    {
209
        static $cE = null;
210
        if (!isset($cE)) {
211
            $cE = & Calendar_Engine_Factory::getEngine();
212
        }
213
        $this->cE     = & $cE;
214
        $this->year   = (int)$y;
215
        $this->month  = (int)$m;
216
        $this->day    = (int)$d;
217
        $this->hour   = (int)$h;
218
        $this->minute = (int)$i;
219
        $this->second = (int)$s;
220
    }
221
222
    /**
223
     * Defines the calendar by a timestamp (Unix or ISO-8601), replacing values
224
     * passed to the constructor
225
     *
226
     * @param int|string $ts Unix or ISO-8601 timestamp
227
     *
228
     * @return void
229
     * @access public
230
     */
231
    function setTimestamp($ts)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
232
    {
233
        $this->year   = $this->cE->stampToYear($ts);
234
        $this->month  = $this->cE->stampToMonth($ts);
235
        $this->day    = $this->cE->stampToDay($ts);
236
        $this->hour   = $this->cE->stampToHour($ts);
237
        $this->minute = $this->cE->stampToMinute($ts);
238
        $this->second = $this->cE->stampToSecond($ts);
239
    }
240
241
    /**
242
     * Returns a timestamp from the current date / time values. Format of
243
     * timestamp depends on Calendar_Engine implementation being used
244
     *
245
     * @return int|string timestamp
246
     * @access public
247
     */
248
    function getTimestamp()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
249
    {
250
        return $this->cE->dateToStamp(
251
            $this->year, $this->month, $this->day,
252
            $this->hour, $this->minute, $this->second);
253
    }
254
255
    /**
256
     * Defines calendar object as selected (e.g. for today)
257
     *
258
     * @param boolean $state whether Calendar subclass
259
     *
260
     * @return void
261
     * @access public
262
     */
263
    function setSelected($state = true)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
264
    {
265
        $this->selected = $state;
266
    }
267
268
    /**
269
     * True if the calendar subclass object is selected (e.g. today)
270
     *
271
     * @return boolean
272
     * @access public
273
     */
274
    function isSelected()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
275
    {
276
        return $this->selected;
277
    }
278
279
    /**
280
     * Checks if the current Calendar object is today's date
281
     *
282
     * @return boolean
283
     * @access public
284
     */
285
    function isToday()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
286
    {
287
        return $this->cE->isToday($this->getTimeStamp());
288
    }
289
290
    /**
291
     * Adjusts the date (helper method)
292
     *
293
     * @return void
294
     * @access public
295
     */
296
    function adjust()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
297
    {
298
        $stamp        = $this->getTimeStamp();
299
        $this->year   = $this->cE->stampToYear($stamp);
300
        $this->month  = $this->cE->stampToMonth($stamp);
301
        $this->day    = $this->cE->stampToDay($stamp);
302
        $this->hour   = $this->cE->stampToHour($stamp);
303
        $this->minute = $this->cE->stampToMinute($stamp);
304
        $this->second = $this->cE->stampToSecond($stamp);
305
    }
306
307
    /**
308
     * Returns the date as an associative array (helper method)
309
     *
310
     * @param mixed $stamp timestamp (leave empty for current timestamp)
311
     *
312
     * @return array
313
     * @access public
314
     */
315
    function toArray($stamp=null)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
316
    {
317
        if (is_null($stamp)) {
318
            $stamp = $this->getTimeStamp();
319
        }
320
        return array(
321
            'year'   => $this->cE->stampToYear($stamp),
322
            'month'  => $this->cE->stampToMonth($stamp),
323
            'day'    => $this->cE->stampToDay($stamp),
324
            'hour'   => $this->cE->stampToHour($stamp),
325
            'minute' => $this->cE->stampToMinute($stamp),
326
            'second' => $this->cE->stampToSecond($stamp)
327
        );
328
    }
329
330
    /**
331
     * Returns the value as an associative array (helper method)
332
     *
333
     * @param string $returnType type of date object that return value represents
334
     * @param string $format     ['int' | 'array' | 'timestamp' | 'object']
335
     * @param mixed  $stamp      timestamp (depending on Calendar engine being used)
336
     * @param int    $default    default value (i.e. give me the answer quick)
337
     *
338
     * @return mixed
339
     * @access private
340
     */
341
    function returnValue($returnType, $format, $stamp, $default)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
342
    {
343
        switch (strtolower($format)) {
344
        case 'int':
345
            return $default;
346
        case 'array':
347
            return $this->toArray($stamp);
348
            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...
349
        case 'object':
350
            include_once CALENDAR_ROOT.'Factory.php';
351
            return Factory::createByTimestamp($returnType, $stamp);
0 ignored issues
show
Bug Best Practice introduced by
The method PEAR\Calendar\Factory::createByTimestamp() is not static, but was called statically. ( Ignorable by Annotation )

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

351
            return Factory::/** @scrutinizer ignore-call */ createByTimestamp($returnType, $stamp);
Loading history...
352
            break;
353
        case 'timestamp':
354
        default:
355
            return $stamp;
356
            break;
357
        }
358
    }
359
360
    /**
361
     * Abstract method for building the children of a calendar object.
362
     * Implemented by Calendar subclasses
363
     *
364
     * @param array $sDates array containing Calendar objects to select (optional)
365
     *
366
     * @return boolean
367
     * @access public
368
     * @abstract
369
     */
370
    function build($sDates = array())
0 ignored issues
show
Unused Code introduced by
The parameter $sDates is not used and could be removed. ( Ignorable by Annotation )

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

370
    function build(/** @scrutinizer ignore-unused */ $sDates = array())

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
371
    {
372
        include_once 'PEAR.php';
373
        PEAR::raiseError('Calendar::build is abstract', null, PEAR_ERROR_TRIGGER,
0 ignored issues
show
Bug introduced by
The type PEAR\Calendar\PEAR was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
Bug introduced by
The constant PEAR\Calendar\PEAR_ERROR_TRIGGER was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
374
            E_USER_NOTICE, 'Calendar::build()');
375
        return false;
376
    }
377
378
    /**
379
     * Abstract method for selected data objects called from build
380
     *
381
     * @param array $sDates array of Calendar objects to select
382
     *
383
     * @return boolean
384
     * @access public
385
     * @abstract
386
     */
387
    function setSelection($sDates)
0 ignored issues
show
Unused Code introduced by
The parameter $sDates is not used and could be removed. ( Ignorable by Annotation )

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

387
    function setSelection(/** @scrutinizer ignore-unused */ $sDates)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
388
    {
389
        include_once 'PEAR.php';
390
        PEAR::raiseError(
391
            'Calendar::setSelection is abstract', null, PEAR_ERROR_TRIGGER,
0 ignored issues
show
Bug introduced by
The constant PEAR\Calendar\PEAR_ERROR_TRIGGER was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
392
            E_USER_NOTICE, 'Calendar::setSelection()');
393
        return false;
394
    }
395
396
    /**
397
     * Iterator method for fetching child Calendar subclass objects
398
     * (e.g. a minute from an hour object). On reaching the end of
399
     * the collection, returns false and resets the collection for
400
     * further iteratations.
401
     *
402
     * @return mixed either an object subclass of Calendar or false
403
     * @access public
404
     */
405
    function fetch()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
406
    {
407
        $child = each($this->children);
0 ignored issues
show
Deprecated Code introduced by
The function each() has been deprecated: 7.2 ( Ignorable by Annotation )

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

407
        $child = /** @scrutinizer ignore-deprecated */ each($this->children);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
408
        if ($child) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $child of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
409
            return $child['value'];
410
        } else {
411
            reset($this->children);
412
            return false;
413
        }
414
    }
415
416
    /**
417
     * Fetches all child from the current collection of children
418
     *
419
     * @return array
420
     * @access public
421
     */
422
    function fetchAll()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
423
    {
424
        return $this->children;
425
    }
426
427
    /**
428
     * Get the number Calendar subclass objects stored in the internal collection
429
     *
430
     * @return int
431
     * @access public
432
     */
433
    function size()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
434
    {
435
        return count($this->children);
436
    }
437
438
    /**
439
     * Determine whether this date is valid, with the bounds determined by
440
     * the Calendar_Engine. The call is passed on to Calendar_Validator::isValid
441
     *
442
     * @return boolean
443
     * @access public
444
     */
445
    function isValid()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
446
    {
447
        $validator = & $this->getValidator();
448
        return $validator->isValid();
449
    }
450
451
    /**
452
     * Returns an instance of Calendar_Validator
453
     *
454
     * @return Validator
455
     * @access public
456
     */
457
    function & getValidator()
458
    {
459
        if (!isset($this->validator)) {
460
            include_once CALENDAR_ROOT.'Validator.php';
461
            $this->validator = new Validator($this);
462
        }
463
        return $this->validator;
464
    }
465
466
    /**
467
     * Returns a reference to the current Calendar_Engine being used. Useful
468
     * for Calendar_Table_Helper and Calendar_Validator
469
     *
470
     * @return object implementing Calendar_Engine_Inteface
471
     * @access protected
472
     */
473
    function & getEngine()
474
    {
475
        return $this->cE;
476
    }
477
478
    /**
479
     * Set the CALENDAR_FIRST_DAY_OF_WEEK constant to the $firstDay value
480
     * if the constant is not set yet.
481
     *
482
     * @param integer $firstDay first day of the week (0=sunday, 1=monday, ...)
483
     *
484
     * @return integer
485
     * @throws E_USER_WARNING this method throws a WARNING if the
486
     *    CALENDAR_FIRST_DAY_OF_WEEK constant is already defined and
487
     *    the $firstDay parameter is set to a different value
488
     * @access protected
489
     */
490
    function defineFirstDayOfWeek($firstDay = null)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
491
    {
492
        if (defined('CALENDAR_FIRST_DAY_OF_WEEK')) {
493
            if (!is_null($firstDay) && ($firstDay != CALENDAR_FIRST_DAY_OF_WEEK)) {
494
                $msg = 'CALENDAR_FIRST_DAY_OF_WEEK constant already defined.'
495
                  .' The $firstDay parameter will be ignored.';
496
                trigger_error($msg, E_USER_WARNING);
497
            }
498
            return CALENDAR_FIRST_DAY_OF_WEEK;
499
        }
500
        if (is_null($firstDay)) {
501
            $firstDay = $this->cE->getFirstDayOfWeek(
502
                $this->thisYear(),
503
                $this->thisMonth(),
504
                $this->thisDay()
505
            );
506
        }
507
        define ('CALENDAR_FIRST_DAY_OF_WEEK', $firstDay);
508
        return CALENDAR_FIRST_DAY_OF_WEEK;
509
    }
510
511
    /**
512
     * Returns the value for the previous year
513
     *
514
     * @param string $format return value format ['int'|'timestamp'|'object'|'array']
515
     *
516
     * @return int e.g. 2002 or timestamp
517
     * @access public
518
     */
519
    function prevYear($format = 'int')
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
520
    {
521
        $ts = $this->cE->dateToStamp($this->year-1, 1, 1, 0, 0, 0);
522
        return $this->returnValue('Year', $format, $ts, $this->year-1);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->returnValu..., $ts, $this->year - 1) also could return the type array|object which is incompatible with the documented return type integer.
Loading history...
523
    }
524
525
    /**
526
     * Returns the value for this year
527
     *
528
     * @param string $format return value format ['int'|'timestamp'|'object'|'array']
529
     *
530
     * @return int e.g. 2003 or timestamp
531
     * @access public
532
     */
533
    function thisYear($format = 'int')
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
534
    {
535
        $ts = $this->cE->dateToStamp($this->year, 1, 1, 0, 0, 0);
536
        return $this->returnValue('Year', $format, $ts, $this->year);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->returnValu...rmat, $ts, $this->year) also could return the type array|object which is incompatible with the documented return type integer.
Loading history...
537
    }
538
539
    /**
540
     * Returns the value for next year
541
     *
542
     * @param string $format return value format ['int'|'timestamp'|'object'|'array']
543
     *
544
     * @return int e.g. 2004 or timestamp
545
     * @access public
546
     */
547
    function nextYear($format = 'int')
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
548
    {
549
        $ts = $this->cE->dateToStamp($this->year+1, 1, 1, 0, 0, 0);
550
        return $this->returnValue('Year', $format, $ts, $this->year+1);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->returnValu..., $ts, $this->year + 1) also could return the type array|object which is incompatible with the documented return type integer.
Loading history...
551
    }
552
553
    /**
554
     * Returns the value for the previous month
555
     *
556
     * @param string $format return value format ['int'|'timestamp'|'object'|'array']
557
     *
558
     * @return int e.g. 4 or Unix timestamp
559
     * @access public
560
     */
561
    function prevMonth($format = 'int')
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
562
    {
563
        $ts = $this->cE->dateToStamp($this->year, $this->month-1, 1, 0, 0, 0);
564
        return $this->returnValue('Month', $format, $ts, $this->cE->stampToMonth($ts));
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->returnValu...>cE->stampToMonth($ts)) also could return the type array|object which is incompatible with the documented return type integer.
Loading history...
565
    }
566
567
    /**
568
     * Returns the value for this month
569
     *
570
     * @param string $format return value format ['int'|'timestamp'|'object'|'array']
571
     *
572
     * @return int e.g. 5 or timestamp
573
     * @access public
574
     */
575
    function thisMonth($format = 'int')
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
576
    {
577
        $ts = $this->cE->dateToStamp($this->year, $this->month, 1, 0, 0, 0);
578
        return $this->returnValue('Month', $format, $ts, $this->month);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->returnValu...mat, $ts, $this->month) also could return the type array|object which is incompatible with the documented return type integer.
Loading history...
579
    }
580
581
    /**
582
     * Returns the value for next month
583
     *
584
     * @param string $format return value format ['int'|'timestamp'|'object'|'array']
585
     *
586
     * @return int e.g. 6 or timestamp
587
     * @access public
588
     */
589
    function nextMonth($format = 'int')
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
590
    {
591
        $ts = $this->cE->dateToStamp($this->year, $this->month+1, 1, 0, 0, 0);
592
        return $this->returnValue('Month', $format, $ts, $this->cE->stampToMonth($ts));
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->returnValu...>cE->stampToMonth($ts)) also could return the type array|object which is incompatible with the documented return type integer.
Loading history...
593
    }
594
595
    /**
596
     * Returns the value for the previous day
597
     *
598
     * @param string $format return value format ['int'|'timestamp'|'object'|'array']
599
     *
600
     * @return int e.g. 10 or timestamp
601
     * @access public
602
     */
603
    function prevDay($format = 'int')
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
604
    {
605
        $ts = $this->cE->dateToStamp(
606
            $this->year, $this->month, $this->day-1, 0, 0, 0);
607
        return $this->returnValue('Day', $format, $ts, $this->cE->stampToDay($ts));
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->returnValu...s->cE->stampToDay($ts)) also could return the type array|object which is incompatible with the documented return type integer.
Loading history...
608
    }
609
610
    /**
611
     * Returns the value for this day
612
     *
613
     * @param string $format return value format ['int'|'timestamp'|'object'|'array']
614
     *
615
     * @return int e.g. 11 or timestamp
616
     * @access public
617
     */
618
    function thisDay($format = 'int')
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
619
    {
620
        $ts = $this->cE->dateToStamp(
621
            $this->year, $this->month, $this->day, 0, 0, 0);
622
        return $this->returnValue('Day', $format, $ts, $this->day);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->returnValu...ormat, $ts, $this->day) also could return the type array|object which is incompatible with the documented return type integer.
Loading history...
623
    }
624
625
    /**
626
     * Returns the value for the next day
627
     *
628
     * @param string $format return value format ['int'|'timestamp'|'object'|'array']
629
     *
630
     * @return int e.g. 12 or timestamp
631
     * @access public
632
     */
633
    function nextDay($format = 'int')
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
634
    {
635
        $ts = $this->cE->dateToStamp(
636
            $this->year, $this->month, $this->day+1, 0, 0, 0);
637
        return $this->returnValue('Day', $format, $ts, $this->cE->stampToDay($ts));
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->returnValu...s->cE->stampToDay($ts)) also could return the type array|object which is incompatible with the documented return type integer.
Loading history...
638
    }
639
640
    /**
641
     * Returns the value for the previous hour
642
     *
643
     * @param string $format return value format ['int'|'timestamp'|'object'|'array']
644
     *
645
     * @return int e.g. 13 or timestamp
646
     * @access public
647
     */
648
    function prevHour($format = 'int')
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
649
    {
650
        $ts = $this->cE->dateToStamp(
651
            $this->year, $this->month, $this->day, $this->hour-1, 0, 0);
652
        return $this->returnValue('Hour', $format, $ts, $this->cE->stampToHour($ts));
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->returnValu...->cE->stampToHour($ts)) also could return the type array|object which is incompatible with the documented return type integer.
Loading history...
653
    }
654
655
    /**
656
     * Returns the value for this hour
657
     *
658
     * @param string $format return value format ['int'|'timestamp'|'object'|'array']
659
     *
660
     * @return int e.g. 14 or timestamp
661
     * @access public
662
     */
663
    function thisHour($format = 'int')
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
664
    {
665
        $ts = $this->cE->dateToStamp(
666
            $this->year, $this->month, $this->day, $this->hour, 0, 0);
667
        return $this->returnValue('Hour', $format, $ts, $this->hour);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->returnValu...rmat, $ts, $this->hour) also could return the type array|object which is incompatible with the documented return type integer.
Loading history...
668
    }
669
670
    /**
671
     * Returns the value for the next hour
672
     *
673
     * @param string $format return value format ['int'|'timestamp'|'object'|'array']
674
     *
675
     * @return int e.g. 14 or timestamp
676
     * @access public
677
     */
678
    function nextHour($format = 'int')
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
679
    {
680
        $ts = $this->cE->dateToStamp(
681
            $this->year, $this->month, $this->day, $this->hour+1, 0, 0);
682
        return $this->returnValue('Hour', $format, $ts, $this->cE->stampToHour($ts));
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->returnValu...->cE->stampToHour($ts)) also could return the type array|object which is incompatible with the documented return type integer.
Loading history...
683
    }
684
685
    /**
686
     * Returns the value for the previous minute
687
     *
688
     * @param string $format return value format ['int'|'timestamp'|'object'|'array']
689
     *
690
     * @return int e.g. 23 or timestamp
691
     * @access public
692
     */
693
    function prevMinute($format = 'int')
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
694
    {
695
        $ts = $this->cE->dateToStamp(
696
            $this->year, $this->month, $this->day,
697
            $this->hour, $this->minute-1, 0);
698
        return $this->returnValue('Minute', $format, $ts, $this->cE->stampToMinute($ts));
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->returnValu...cE->stampToMinute($ts)) also could return the type array|object which is incompatible with the documented return type integer.
Loading history...
699
    }
700
701
    /**
702
     * Returns the value for this minute
703
     *
704
     * @param string $format return value format ['int'|'timestamp'|'object'|'array']
705
     *
706
     * @return int e.g. 24 or timestamp
707
     * @access public
708
     */
709
    function thisMinute($format = 'int')
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
710
    {
711
        $ts = $this->cE->dateToStamp(
712
            $this->year, $this->month, $this->day,
713
            $this->hour, $this->minute, 0);
714
        return $this->returnValue('Minute', $format, $ts, $this->minute);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->returnValu...at, $ts, $this->minute) also could return the type array|object which is incompatible with the documented return type integer.
Loading history...
715
    }
716
717
    /**
718
    * Returns the value for the next minute
719
    *
720
     * @param string $format return value format ['int'|'timestamp'|'object'|'array']
721
     *
722
     * @return int e.g. 25 or timestamp
723
     * @access public
724
     */
725
    function nextMinute($format = 'int')
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
726
    {
727
        $ts = $this->cE->dateToStamp(
728
            $this->year, $this->month, $this->day,
729
            $this->hour, $this->minute+1, 0);
730
        return $this->returnValue('Minute', $format, $ts, $this->cE->stampToMinute($ts));
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->returnValu...cE->stampToMinute($ts)) also could return the type array|object which is incompatible with the documented return type integer.
Loading history...
731
    }
732
733
    /**
734
     * Returns the value for the previous second
735
     *
736
     * @param string $format return value format ['int'|'timestamp'|'object'|'array']
737
     *
738
     * @return int e.g. 43 or timestamp
739
     * @access public
740
     */
741
    function prevSecond($format = 'int')
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
742
    {
743
        $ts = $this->cE->dateToStamp(
744
            $this->year, $this->month, $this->day,
745
            $this->hour, $this->minute, $this->second-1);
746
        return $this->returnValue('Second', $format, $ts, $this->cE->stampToSecond($ts));
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->returnValu...cE->stampToSecond($ts)) also could return the type array|object which is incompatible with the documented return type integer.
Loading history...
747
    }
748
749
    /**
750
     * Returns the value for this second
751
     *
752
    * @param string $format return value format ['int'|'timestamp'|'object'|'array']
753
    *
754
     * @return int e.g. 44 or timestamp
755
     * @access public
756
     */
757
    function thisSecond($format = 'int')
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
758
    {
759
        $ts = $this->cE->dateToStamp(
760
            $this->year, $this->month, $this->day,
761
            $this->hour, $this->minute, $this->second);
762
        return $this->returnValue('Second', $format, $ts, $this->second);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->returnValu...at, $ts, $this->second) also could return the type array|object which is incompatible with the documented return type integer.
Loading history...
763
    }
764
765
    /**
766
     * Returns the value for the next second
767
     *
768
     * @param string $format return value format ['int'|'timestamp'|'object'|'array']
769
     *
770
     * @return int e.g. 45 or timestamp
771
     * @access public
772
     */
773
    function nextSecond($format = 'int')
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
774
    {
775
        $ts = $this->cE->dateToStamp(
776
            $this->year, $this->month, $this->day,
777
            $this->hour, $this->minute, $this->second+1);
778
        return $this->returnValue('Second', $format, $ts, $this->cE->stampToSecond($ts));
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->returnValu...cE->stampToSecond($ts)) also could return the type array|object which is incompatible with the documented return type integer.
Loading history...
779
    }
780
}
781