SystemTimeProvider   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 4
c 1
b 0
f 0
dl 0
loc 23
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getCurrentTime() 0 3 1
1
<?php
2
3
/*
4
 * event (https://github.com/phpgears/event).
5
 * Event handling.
6
 *
7
 * @license MIT
8
 * @link https://github.com/phpgears/event
9
 * @author Julián Gutiérrez <[email protected]>
10
 */
11
12
declare(strict_types=1);
13
14
namespace Gears\Event\Time;
15
16
/**
17
 * General system time provider.
18
 */
19
final class SystemTimeProvider implements TimeProvider
20
{
21
    /**
22
     * @var \DateTimeZone
23
     */
24
    private $timeZone;
25
26
    /**
27
     * SystemTimeProvider constructor.
28
     *
29
     * @param \DateTimeZone|null $timeZone
30
     */
31
    public function __construct(?\DateTimeZone $timeZone = null)
32
    {
33
        $this->timeZone = $timeZone ?? new \DateTimeZone('UTC');
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function getCurrentTime(): \DateTimeImmutable
40
    {
41
        return new \DateTimeImmutable('now', $this->timeZone);
42
    }
43
}
44