Completed
Push — master ( 72df4e...61b60d )
by Jesse
01:50
created

TimeZoneAwareMutableClock   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 17
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A now() 0 3 1
A in() 0 3 1
A __construct() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\Clock;
4
5
use DateTime;
6
use DateTimeInterface;
7
use DateTimeZone;
8
9
/**
10
 * TImeZoneAwareMutableClock. This clock is just like a regular mutable clock,
11
 * except that it knows in which time zone it operates.
12
 *
13
 * @author Stratadox
14
 */
15
final class TimeZoneAwareMutableClock implements Clock
16
{
17
    private $timeZone;
18
19
    public function __construct(DateTimeZone $timeZone)
20
    {
21
        $this->timeZone = $timeZone;
22
    }
23
24
    public static function in(DateTimeZone $timeZone): self
25
    {
26
        return new self($timeZone);
27
    }
28
29
    public function now(): DateTimeInterface
30
    {
31
        return new DateTime('now', $this->timeZone);
32
    }
33
}
34