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

StuTime::date()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 3
cts 3
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 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