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

StuTime::hrtime()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
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