Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
25 / 25 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
ExchangePeriod | |
100.00% |
25 / 25 |
|
100.00% |
4 / 4 |
18 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
3 | |||
getStartDateTime | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
9 | |||
getEndDateTime | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
4 | |||
getPeriodIdentifier | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace BO\Zmsapi\Helper; |
4 | |
5 | use BO\Slim\Render; |
6 | |
7 | /** |
8 | * |
9 | * @SuppressWarnings(CouplingBetweenObjects) |
10 | */ |
11 | class ExchangePeriod |
12 | { |
13 | protected static $year = ''; |
14 | |
15 | protected static $month = ''; |
16 | |
17 | protected static $day = ''; |
18 | |
19 | protected static $periodIdentifier = 'day'; |
20 | |
21 | protected static $startDateTime = null; |
22 | |
23 | protected static $endDateTime = null; |
24 | |
25 | public function __construct($period) |
26 | { |
27 | $periodArr = preg_split('%(-)%', $period); |
28 | static::$year = $periodArr[0]; |
29 | static::$month = (isset($periodArr[1])) ? $periodArr[1] : ''; |
30 | static::$day = (isset($periodArr[2])) ? $periodArr[2] : ''; |
31 | } |
32 | |
33 | public function getStartDateTime() |
34 | { |
35 | if ('_' == static::$year) { |
36 | static::$periodIdentifier = 'hour'; |
37 | static::$startDateTime = \App::$now; |
38 | } elseif (static::$year && static::$month && static::$day) { |
39 | static::$periodIdentifier = 'hour'; |
40 | static::$startDateTime = new \DateTimeImmutable(static::$year . '-' . static::$month . '-' . static::$day); |
41 | } elseif (static::$year && static::$month && ! static::$day) { |
42 | static::$periodIdentifier = 'day'; |
43 | static::$startDateTime = new \DateTimeImmutable(static::$year . '-' . static::$month . '-01'); |
44 | } elseif (! static::$month) { |
45 | static::$periodIdentifier = 'month'; |
46 | static::$startDateTime = new \DateTimeImmutable(static::$year . '-01-01'); |
47 | } |
48 | return static::$startDateTime; |
49 | } |
50 | |
51 | public function getEndDateTime() |
52 | { |
53 | if ('hour' == static::$periodIdentifier) { |
54 | static::$endDateTime = static::$startDateTime; |
55 | } elseif ('day' == static::$periodIdentifier) { |
56 | static::$endDateTime = static::$startDateTime->modify('last day of this month'); |
57 | } elseif ('month' == static::$periodIdentifier) { |
58 | static::$endDateTime = new \DateTimeImmutable(static::$year . '-12-31'); |
59 | } |
60 | return static::$endDateTime; |
61 | } |
62 | |
63 | public function getPeriodIdentifier($groupby) |
64 | { |
65 | return ($groupby) ? $groupby : static::$periodIdentifier; |
66 | } |
67 | } |