| Conditions | 7 |
| Paths | 7 |
| Total Lines | 29 |
| Code Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 22 |
| CRAP Score | 7 |
| Changes | 0 | ||
| 1 | <?php |
||
| 21 | 2 | public static function getValueForTag(string $timeContext, ?\DateTime $date = null): int |
|
| 22 | {
|
||
| 23 | 2 | $date = $date ?? new \DateTime(); |
|
| 24 | |||
| 25 | switch ($timeContext) {
|
||
| 26 | 2 | case Tag::YEAR: |
|
| 27 | 1 | $res = $date->format('Y');
|
|
| 28 | 1 | break; |
|
| 29 | 2 | case Tag::SEMESTER: |
|
| 30 | 1 | $res = ceil($date->format('n') / 6);
|
|
| 31 | 1 | break; |
|
| 32 | 2 | case Tag::QUARTER: |
|
| 33 | 1 | $res = ceil($date->format('n') / 3);
|
|
| 34 | 1 | break; |
|
| 35 | 2 | case Tag::MONTH: |
|
| 36 | 1 | $res = $date->format('m');
|
|
| 37 | 1 | break; |
|
| 38 | 2 | case Tag::WEEK: |
|
| 39 | 1 | $res = $date->format('W');
|
|
| 40 | 1 | break; |
|
| 41 | 2 | case Tag::DAY: |
|
| 42 | 1 | $res = $date->format('z');
|
|
| 43 | 1 | break; |
|
| 44 | default: |
||
| 45 | 1 | throw new \InvalidArgumentException('Time context tag not allowed');
|
|
| 46 | break; |
||
| 47 | } |
||
| 48 | |||
| 49 | 1 | return (int)$res; |
|
| 50 | } |
||
| 54 |