Passed
Push — master ( 8cd431...bc71f5 )
by Janko
09:12
created

StuTime::transformToStuDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 1
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