Passed
Push — master ( d2520f...3f8ec2 )
by Michael
02:50
created

Calendar   B

Complexity

Total Complexity 48

Size/Duplication

Total Lines 615
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 48
dl 0
loc 615
rs 8.4291
c 0
b 0
f 0

36 Methods

Rating   Name   Duplication   Size   Complexity  
A getValidator() 0 8 2
A getTimestamp() 0 3 1
A isSelected() 0 3 1
A fetch() 0 9 2
A nextYear() 0 5 1
A prevMinute() 0 5 1
A getEngine() 0 3 1
A adjust() 0 9 1
A prevHour() 0 5 1
A isToday() 0 3 1
A thisMinute() 0 5 1
A fetchAll() 0 3 1
A prevYear() 0 5 1
A thisHour() 0 5 1
A prevMonth() 0 5 1
B returnValue() 0 17 5
A setTimestamp() 0 8 1
A build() 0 6 1
A size() 0 3 1
A prevDay() 0 5 1
A setSelected() 0 3 1
A setSelection() 0 6 1
A thisMonth() 0 5 1
A thisYear() 0 5 1
A toArray() 0 13 2
A thisSecond() 0 5 1
B defineFirstDayOfWeek() 0 16 5
A nextSecond() 0 5 1
A isValid() 0 5 1
A nextMonth() 0 5 1
A nextDay() 0 5 1
A nextHour() 0 5 1
A nextMinute() 0 5 1
A prevSecond() 0 5 1
A __construct() 0 13 2
A thisDay() 0 5 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
3
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5
/**
6
 * Contains the Calendar and Calendar_Engine_Factory classes.
7
 *
8
 * PHP versions 4 and 5
9
 *
10
 * LICENSE: Redistribution and use in source and binary forms, with or without
11
 * modification, are permitted provided that the following conditions are met:
12
 * 1. Redistributions of source code must retain the above copyright
13
 *    notice, this list of conditions and the following disclaimer.
14
 * 2. Redistributions in binary form must reproduce the above copyright
15
 *    notice, this list of conditions and the following disclaimer in the
16
 *    documentation and/or other materials provided with the distribution.
17
 * 3. The name of the author may not be used to endorse or promote products
18
 *    derived from this software without specific prior written permission.
19
 *
20
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
21
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23
 * IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
24
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
 *
31
 * @category  Date and Time
32
 *
33
 * @author    Harry Fuecks <[email protected]>
34
 * @author    Lorenzo Alberton <[email protected]>
35
 * @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
36
 * @license   http://www.debian.org/misc/bsd.license  BSD License (3 Clause)
37
 *
38
 * @link      http://pear.php.net/package/Calendar
39
 */
40
41
/**
42
 * Allows Calendar include path to be redefined.
43
 */
44
if (!defined('CALENDAR_ROOT')) {
45
    define('CALENDAR_ROOT', 'Calendar/');
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
 *
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
 *
76
 * @link      http://pear.php.net/package/Calendar
77
 * @see       Calendar_Engine_Interface
78
 */
79
class Calendar_Engine_Factory
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
80
{
81
    /**
82
     * Returns an instance of the engine.
83
     *
84
     * @return object instance of a calendar calculation engine
85
     */
86
    public static function &getEngine()
87
    {
88
        static $engine = false;
89
        switch (CALENDAR_ENGINE) {
90
            case 'PearDate':
91
                $class = 'Calendar_Engine_PearDate';
92
                break;
93
            case 'UnixTS':
94
            default:
95
                $class = 'Calendar_Engine_UnixTS';
96
                break;
97
        }
98
        if (!$engine) {
99
            if (!class_exists($class)) {
100
                require_once CALENDAR_ROOT . 'Engine' . '/' . CALENDAR_ENGINE . '.php';
101
            }
102
            $engine = new $class();
103
        }
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
 *
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
 *
119
 * @link      http://pear.php.net/package/Calendar
120
 * @abstract
121
 */
122
class Calendar
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
123
{
124
    /**
125
     * Instance of class implementing calendar engine interface.
126
     *
127
     * @var object
128
     */
129
    public $cE;
130
131
    /**
132
     * Instance of Calendar_Validator (lazy initialized when isValid() or
133
     * getValidor() is called.
134
     *
135
     * @var Calendar_Validator
136
     */
137
    public $validator;
138
139
    /**
140
     * Year for this calendar object e.g. 2003.
141
     *
142
     * @var int
143
     */
144
    public $year;
145
146
    /**
147
     * Month for this calendar object e.g. 9.
148
     *
149
     * @var int
150
     */
151
    public $month;
152
153
    /**
154
     * Day of month for this calendar object e.g. 23.
155
     *
156
     * @var int
157
     */
158
    public $day;
159
160
    /**
161
     * Hour of day for this calendar object e.g. 13.
162
     *
163
     * @var int
164
     */
165
    public $hour;
166
167
    /**
168
     * Minute of hour this calendar object e.g. 46.
169
     *
170
     * @var int
171
     */
172
    public $minute;
173
174
    /**
175
     * Second of minute this calendar object e.g. 34.
176
     *
177
     * @var int
178
     */
179
    public $second;
180
181
    /**
182
     * Marks this calendar object as selected (e.g. 'today').
183
     *
184
     * @var bool
185
     */
186
    public $selected = false;
187
188
    /**
189
     * Collection of child calendar objects created from subclasses
190
     * of Calendar. Type depends on the object which created them.
191
     *
192
     * @var array
193
     */
194
    public $children = [];
195
196
    /**
197
     * Constructs the Calendar.
198
     *
199
     * @param int $y year
200
     * @param int $m month
201
     * @param int $d day
202
     * @param int $h hour
203
     * @param int $i minute
204
     * @param int $s second
205
     */
206
    public function __construct($y = 2000, $m = 1, $d = 1, $h = 0, $i = 0, $s = 0)
207
    {
208
        static $cE = null;
209
        if (!isset($cE)) {
210
            $cE = Calendar_Engine_Factory::getEngine();
211
        }
212
        $this->cE     =& $cE;
213
        $this->year   = (int)$y;
214
        $this->month  = (int)$m;
215
        $this->day    = (int)$d;
216
        $this->hour   = (int)$h;
217
        $this->minute = (int)$i;
218
        $this->second = (int)$s;
219
    }
220
221
    /**
222
     * Defines the calendar by a timestamp (Unix or ISO-8601), replacing values
223
     * passed to the constructor.
224
     *
225
     * @param int|string $ts Unix or ISO-8601 timestamp
226
     */
227
    public function setTimestamp($ts)
228
    {
229
        $this->year   = $this->cE->stampToYear($ts);
230
        $this->month  = $this->cE->stampToMonth($ts);
231
        $this->day    = $this->cE->stampToDay($ts);
232
        $this->hour   = $this->cE->stampToHour($ts);
233
        $this->minute = $this->cE->stampToMinute($ts);
234
        $this->second = $this->cE->stampToSecond($ts);
235
    }
236
237
    /**
238
     * Returns a timestamp from the current date / time values. Format of
239
     * timestamp depends on Calendar_Engine implementation being used.
240
     *
241
     * @return int|string timestamp
242
     */
243
    public function getTimestamp()
244
    {
245
        return $this->cE->dateToStamp($this->year, $this->month, $this->day, $this->hour, $this->minute, $this->second);
246
    }
247
248
    /**
249
     * Defines calendar object as selected (e.g. for today).
250
     *
251
     * @param bool $state whether Calendar subclass
252
     */
253
    public function setSelected($state = true)
254
    {
255
        $this->selected = $state;
256
    }
257
258
    /**
259
     * True if the calendar subclass object is selected (e.g. today).
260
     *
261
     * @return bool
262
     */
263
    public function isSelected()
264
    {
265
        return $this->selected;
266
    }
267
268
    /**
269
     * Checks if the current Calendar object is today's date.
270
     *
271
     * @return bool
272
     */
273
    public function isToday()
274
    {
275
        return $this->cE->isToday($this->getTimestamp());
276
    }
277
278
    /**
279
     * Adjusts the date (helper method).
280
     */
281
    public function adjust()
282
    {
283
        $stamp        = $this->getTimestamp();
284
        $this->year   = $this->cE->stampToYear($stamp);
285
        $this->month  = $this->cE->stampToMonth($stamp);
286
        $this->day    = $this->cE->stampToDay($stamp);
287
        $this->hour   = $this->cE->stampToHour($stamp);
288
        $this->minute = $this->cE->stampToMinute($stamp);
289
        $this->second = $this->cE->stampToSecond($stamp);
290
    }
291
292
    /**
293
     * Returns the date as an associative array (helper method).
294
     *
295
     * @param mixed $stamp timestamp (leave empty for current timestamp)
296
     *
297
     * @return array
298
     */
299
    public function toArray($stamp = null)
300
    {
301
        if (is_null($stamp)) {
302
            $stamp = $this->getTimestamp();
303
        }
304
305
        return [
306
            'year'   => $this->cE->stampToYear($stamp),
307
            'month'  => $this->cE->stampToMonth($stamp),
308
            'day'    => $this->cE->stampToDay($stamp),
309
            'hour'   => $this->cE->stampToHour($stamp),
310
            'minute' => $this->cE->stampToMinute($stamp),
311
            'second' => $this->cE->stampToSecond($stamp),
312
        ];
313
    }
314
315
    /**
316
     * Returns the value as an associative array (helper method).
317
     *
318
     * @param string $returnType type of date object that return value represents
319
     * @param string $format     ['int' | 'array' | 'timestamp' | 'object']
320
     * @param mixed  $stamp      timestamp (depending on Calendar engine being used)
321
     * @param int    $default    default value (i.e. give me the answer quick)
322
     *
323
     * @return mixed
324
     */
325
    public function returnValue($returnType, $format, $stamp, $default)
326
    {
327
        switch (strtolower($format)) {
328
            case 'int':
329
                return $default;
330
            case 'array':
331
                return $this->toArray($stamp);
332
                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...
333
            case 'object':
334
                require_once CALENDAR_ROOT . 'Factory.php';
335
336
                return Calendar_Factory::createByTimestamp($returnType, $stamp);
337
                break;
338
            case 'timestamp':
339
            default:
340
                return $stamp;
341
                break;
342
        }
343
    }
344
345
    /**
346
     * Abstract method for building the children of a calendar object.
347
     * Implemented by Calendar subclasses.
348
     *
349
     * @param array $sDates array containing Calendar objects to select (optional)
350
     *
351
     * @return bool
352
     * @abstract
353
     */
354
    public function build($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

354
    public function build(/** @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...
355
    {
356
        require_once __DIR__ . '/PEAR.php';
357
        PEAR::raiseError('Calendar::build is abstract', null, PEAR_ERROR_TRIGGER, E_USER_NOTICE, 'Calendar::build()');
0 ignored issues
show
Bug introduced by
The type 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_ERROR_TRIGGER was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
358
359
        return false;
360
    }
361
362
    /**
363
     * Abstract method for selected data objects called from build.
364
     *
365
     * @param array $sDates array of Calendar objects to select
366
     *
367
     * @return bool
368
     * @abstract
369
     */
370
    public 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

370
    public 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...
371
    {
372
        require_once __DIR__ . '/PEAR.php';
373
        PEAR::raiseError('Calendar::setSelection is abstract', null, PEAR_ERROR_TRIGGER, E_USER_NOTICE, 'Calendar::setSelection()');
0 ignored issues
show
Bug introduced by
The constant PEAR_ERROR_TRIGGER was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
374
375
        return false;
376
    }
377
378
    /**
379
     * Iterator method for fetching child Calendar subclass objects
380
     * (e.g. a minute from an hour object). On reaching the end of
381
     * the collection, returns false and resets the collection for
382
     * further iteratations.
383
     *
384
     * @return mixed either an object subclass of Calendar or false
385
     */
386
    public function fetch()
387
    {
388
        $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

388
        $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...
389
        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...
390
            return $child['value'];
391
        } else {
392
            reset($this->children);
393
394
            return false;
395
        }
396
    }
397
398
    /**
399
     * Fetches all child from the current collection of children.
400
     *
401
     * @return array
402
     */
403
    public function fetchAll()
404
    {
405
        return $this->children;
406
    }
407
408
    /**
409
     * Get the number Calendar subclass objects stored in the internal collection.
410
     *
411
     * @return int
412
     */
413
    public function size()
414
    {
415
        return count($this->children);
416
    }
417
418
    /**
419
     * Determine whether this date is valid, with the bounds determined by
420
     * the Calendar_Engine. The call is passed on to Calendar_Validator::isValid.
421
     *
422
     * @return bool
423
     */
424
    public function isValid()
425
    {
426
        $validator = $this->getValidator();
427
428
        return $validator->isValid();
429
    }
430
431
    /**
432
     * Returns an instance of Calendar_Validator.
433
     *
434
     * @return Calendar_Validator
435
     */
436
    public function &getValidator()
437
    {
438
        if (!isset($this->validator)) {
439
            require_once CALENDAR_ROOT . 'Validator.php';
440
            $this->validator = new Calendar_Validator($this);
441
        }
442
443
        return $this->validator;
444
    }
445
446
    /**
447
     * Returns a reference to the current Calendar_Engine being used. Useful
448
     * for Calendar_Table_Helper and Calendar_Validator.
449
     *
450
     * @return object implementing Calendar_Engine_Inteface
451
     */
452
    public function &getEngine()
453
    {
454
        return $this->cE;
455
    }
456
457
    /**
458
     * Set the CALENDAR_FIRST_DAY_OF_WEEK constant to the $firstDay value
459
     * if the constant is not set yet.
460
     *
461
     * @param int $firstDay first day of the week (0=sunday, 1=monday, ...)
462
     *
463
     * @return int
464
     *
465
     * @throws E_USER_WARNING this method throws a WARNING if the
466
     *                        CALENDAR_FIRST_DAY_OF_WEEK constant is already defined and
467
     *                        the $firstDay parameter is set to a different value
468
     */
469
    public function defineFirstDayOfWeek($firstDay = null)
470
    {
471
        if (defined('CALENDAR_FIRST_DAY_OF_WEEK')) {
472
            if ((CALENDAR_FIRST_DAY_OF_WEEK != $firstDay) && !is_null($firstDay)) {
473
                $msg = 'CALENDAR_FIRST_DAY_OF_WEEK constant already defined.' . ' The $firstDay parameter will be ignored.';
474
                trigger_error($msg, E_USER_WARNING);
475
            }
476
477
            return CALENDAR_FIRST_DAY_OF_WEEK;
478
        }
479
        if (is_null($firstDay)) {
480
            $firstDay = $this->cE->getFirstDayOfWeek($this->thisYear(), $this->thisMonth(), $this->thisDay());
481
        }
482
        define('CALENDAR_FIRST_DAY_OF_WEEK', $firstDay);
483
484
        return CALENDAR_FIRST_DAY_OF_WEEK;
485
    }
486
487
    /**
488
     * Returns the value for the previous year.
489
     *
490
     * @param string $format return value format ['int'|'timestamp'|'object'|'array']
491
     *
492
     * @return int e.g. 2002 or timestamp
493
     */
494
    public function prevYear($format = 'int')
495
    {
496
        $ts = $this->cE->dateToStamp($this->year - 1, 1, 1, 0, 0, 0);
497
498
        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 object|array which is incompatible with the documented return type integer.
Loading history...
499
    }
500
501
    /**
502
     * Returns the value for this year.
503
     *
504
     * @param string $format return value format ['int'|'timestamp'|'object'|'array']
505
     *
506
     * @return int e.g. 2003 or timestamp
507
     */
508
    public function thisYear($format = 'int')
509
    {
510
        $ts = $this->cE->dateToStamp($this->year, 1, 1, 0, 0, 0);
511
512
        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 object|array which is incompatible with the documented return type integer.
Loading history...
513
    }
514
515
    /**
516
     * Returns the value for next year.
517
     *
518
     * @param string $format return value format ['int'|'timestamp'|'object'|'array']
519
     *
520
     * @return int e.g. 2004 or timestamp
521
     */
522
    public function nextYear($format = 'int')
523
    {
524
        $ts = $this->cE->dateToStamp($this->year + 1, 1, 1, 0, 0, 0);
525
526
        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 object|array which is incompatible with the documented return type integer.
Loading history...
527
    }
528
529
    /**
530
     * Returns the value for the previous month.
531
     *
532
     * @param string $format return value format ['int'|'timestamp'|'object'|'array']
533
     *
534
     * @return int e.g. 4 or Unix timestamp
535
     */
536
    public function prevMonth($format = 'int')
537
    {
538
        $ts = $this->cE->dateToStamp($this->year, $this->month - 1, 1, 0, 0, 0);
539
540
        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 object|array which is incompatible with the documented return type integer.
Loading history...
541
    }
542
543
    /**
544
     * Returns the value for this month.
545
     *
546
     * @param string $format return value format ['int'|'timestamp'|'object'|'array']
547
     *
548
     * @return int e.g. 5 or timestamp
549
     */
550
    public function thisMonth($format = 'int')
551
    {
552
        $ts = $this->cE->dateToStamp($this->year, $this->month, 1, 0, 0, 0);
553
554
        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 object|array which is incompatible with the documented return type integer.
Loading history...
555
    }
556
557
    /**
558
     * Returns the value for next month.
559
     *
560
     * @param string $format return value format ['int'|'timestamp'|'object'|'array']
561
     *
562
     * @return int e.g. 6 or timestamp
563
     */
564
    public function nextMonth($format = 'int')
565
    {
566
        $ts = $this->cE->dateToStamp($this->year, $this->month + 1, 1, 0, 0, 0);
567
568
        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 object|array which is incompatible with the documented return type integer.
Loading history...
569
    }
570
571
    /**
572
     * Returns the value for the previous day.
573
     *
574
     * @param string $format return value format ['int'|'timestamp'|'object'|'array']
575
     *
576
     * @return int e.g. 10 or timestamp
577
     */
578
    public function prevDay($format = 'int')
579
    {
580
        $ts = $this->cE->dateToStamp($this->year, $this->month, $this->day - 1, 0, 0, 0);
581
582
        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 object|array which is incompatible with the documented return type integer.
Loading history...
583
    }
584
585
    /**
586
     * Returns the value for this day.
587
     *
588
     * @param string $format return value format ['int'|'timestamp'|'object'|'array']
589
     *
590
     * @return int e.g. 11 or timestamp
591
     */
592
    public function thisDay($format = 'int')
593
    {
594
        $ts = $this->cE->dateToStamp($this->year, $this->month, $this->day, 0, 0, 0);
595
596
        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 object|array which is incompatible with the documented return type integer.
Loading history...
597
    }
598
599
    /**
600
     * Returns the value for the next day.
601
     *
602
     * @param string $format return value format ['int'|'timestamp'|'object'|'array']
603
     *
604
     * @return int e.g. 12 or timestamp
605
     */
606
    public function nextDay($format = 'int')
607
    {
608
        $ts = $this->cE->dateToStamp($this->year, $this->month, $this->day + 1, 0, 0, 0);
609
610
        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 object|array which is incompatible with the documented return type integer.
Loading history...
611
    }
612
613
    /**
614
     * Returns the value for the previous hour.
615
     *
616
     * @param string $format return value format ['int'|'timestamp'|'object'|'array']
617
     *
618
     * @return int e.g. 13 or timestamp
619
     */
620
    public function prevHour($format = 'int')
621
    {
622
        $ts = $this->cE->dateToStamp($this->year, $this->month, $this->day, $this->hour - 1, 0, 0);
623
624
        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 object|array which is incompatible with the documented return type integer.
Loading history...
625
    }
626
627
    /**
628
     * Returns the value for this hour.
629
     *
630
     * @param string $format return value format ['int'|'timestamp'|'object'|'array']
631
     *
632
     * @return int e.g. 14 or timestamp
633
     */
634
    public function thisHour($format = 'int')
635
    {
636
        $ts = $this->cE->dateToStamp($this->year, $this->month, $this->day, $this->hour, 0, 0);
637
638
        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 object|array which is incompatible with the documented return type integer.
Loading history...
639
    }
640
641
    /**
642
     * Returns the value for the next hour.
643
     *
644
     * @param string $format return value format ['int'|'timestamp'|'object'|'array']
645
     *
646
     * @return int e.g. 14 or timestamp
647
     */
648
    public function nextHour($format = 'int')
649
    {
650
        $ts = $this->cE->dateToStamp($this->year, $this->month, $this->day, $this->hour + 1, 0, 0);
651
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 object|array which is incompatible with the documented return type integer.
Loading history...
653
    }
654
655
    /**
656
     * Returns the value for the previous minute.
657
     *
658
     * @param string $format return value format ['int'|'timestamp'|'object'|'array']
659
     *
660
     * @return int e.g. 23 or timestamp
661
     */
662
    public function prevMinute($format = 'int')
663
    {
664
        $ts = $this->cE->dateToStamp($this->year, $this->month, $this->day, $this->hour, $this->minute - 1, 0);
665
666
        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 object|array which is incompatible with the documented return type integer.
Loading history...
667
    }
668
669
    /**
670
     * Returns the value for this minute.
671
     *
672
     * @param string $format return value format ['int'|'timestamp'|'object'|'array']
673
     *
674
     * @return int e.g. 24 or timestamp
675
     */
676
    public function thisMinute($format = 'int')
677
    {
678
        $ts = $this->cE->dateToStamp($this->year, $this->month, $this->day, $this->hour, $this->minute, 0);
679
680
        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 object|array which is incompatible with the documented return type integer.
Loading history...
681
    }
682
683
    /**
684
     * Returns the value for the next minute.
685
     *
686
     * @param string $format return value format ['int'|'timestamp'|'object'|'array']
687
     *
688
     * @return int e.g. 25 or timestamp
689
     */
690
    public function nextMinute($format = 'int')
691
    {
692
        $ts = $this->cE->dateToStamp($this->year, $this->month, $this->day, $this->hour, $this->minute + 1, 0);
693
694
        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 object|array which is incompatible with the documented return type integer.
Loading history...
695
    }
696
697
    /**
698
     * Returns the value for the previous second.
699
     *
700
     * @param string $format return value format ['int'|'timestamp'|'object'|'array']
701
     *
702
     * @return int e.g. 43 or timestamp
703
     */
704
    public function prevSecond($format = 'int')
705
    {
706
        $ts = $this->cE->dateToStamp($this->year, $this->month, $this->day, $this->hour, $this->minute, $this->second - 1);
707
708
        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 object|array which is incompatible with the documented return type integer.
Loading history...
709
    }
710
711
    /**
712
     * Returns the value for this second.
713
     *
714
     * @param string $format return value format ['int'|'timestamp'|'object'|'array']
715
     *
716
     * @return int e.g. 44 or timestamp
717
     */
718
    public function thisSecond($format = 'int')
719
    {
720
        $ts = $this->cE->dateToStamp($this->year, $this->month, $this->day, $this->hour, $this->minute, $this->second);
721
722
        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 object|array which is incompatible with the documented return type integer.
Loading history...
723
    }
724
725
    /**
726
     * Returns the value for the next second.
727
     *
728
     * @param string $format return value format ['int'|'timestamp'|'object'|'array']
729
     *
730
     * @return int e.g. 45 or timestamp
731
     */
732
    public function nextSecond($format = 'int')
733
    {
734
        $ts = $this->cE->dateToStamp($this->year, $this->month, $this->day, $this->hour, $this->minute, $this->second + 1);
735
736
        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 object|array which is incompatible with the documented return type integer.
Loading history...
737
    }
738
}
739