Passed
Push — dev ( 219c54...831a1f )
by Janko
08:28
created

StuTime   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 57.89%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 39
ccs 11
cts 19
cp 0.5789
rs 10
c 0
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A time() 0 3 1
A transformToStuDateTime() 0 6 1
A date() 0 3 1
A hrtime() 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
    }
18
19
    public function hrtime(): int
20
    {
21
        return hrtime(true);
22
    }
23
24
    public function date(string $format): string
25
    {
26
        return date($format);
27
    }
28
29
    public function dateTime(): DateTime
30
    {
31
        return new DateTime();
32
    }
33
34 2
    public function transformToStuDate(int $unixTimestamp): string
35
    {
36 2
        return sprintf(
37 2
            '%s%s',
38 2
            date('d.m.', $unixTimestamp),
39 2
            (int)date("Y", $unixTimestamp) + StuTime::STU_YEARS_IN_FUTURE_OFFSET,
40 2
        );
41
    }
42
43 1
    public function transformToStuDateTime(int $unixTimestamp): string
44
    {
45 1
        return sprintf(
46 1
            '%s %s',
47 1
            $this->transformToStuDate($unixTimestamp),
48 1
            date("H:i", $unixTimestamp)
49 1
        );
50
    }
51
}
52