Test Failed
Push — dev ( 17f6d8...392257 )
by Janko
10:17 queued 12s
created

StuTime   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 34
ccs 12
cts 14
cp 0.8571
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A transformToStuDateTime() 0 6 1
A date() 0 3 1
A time() 0 3 1
A transformToStuDate() 0 6 1
A dateTime() 0 3 1
1
<?php
2
3
namespace Stu\Module\Control;
4
5
use DateTime;
6
7
/**
8
 * This class adds the possibility to inject a timestamp generator
9
 */
10
class StuTime
11
{
12
    public const STU_YEARS_IN_FUTURE_OFFSET = 370;
13
14
    public function time(): int
15
    {
16
        return time();
17 2
    }
18
19 2
    public function date(string $format): string
20 2
    {
21 2
        return date($format);
22 2
    }
23 2
24
    public function dateTime(): DateTime
25
    {
26 1
        return new DateTime();
27
    }
28 1
29 1
    public function transformToStuDate(int $unixTimestamp): string
30 1
    {
31 1
        return sprintf(
32 1
            '%s%s',
33
            date('d.m.', $unixTimestamp),
34
            (int)date("Y", $unixTimestamp) + StuTime::STU_YEARS_IN_FUTURE_OFFSET,
35
        );
36
    }
37
38
    public function transformToStuDateTime(int $unixTimestamp): string
39
    {
40
        return sprintf(
41
            '%s %s',
42
            $this->transformToStuDate($unixTimestamp),
43
            date("H:i", $unixTimestamp)
44
        );
45
    }
46
}
47