Completed
Pull Request — develop (#24)
by Michael
02:08
created

AbstractProvider::getCurrentTimestamp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 0
cts 1
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * This file is part of the Teazee package.
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @license    MIT License
9
 */
10
namespace Teazee\Provider;
11
12
use DateTimeImmutable;
13
use DateTimeZone;
14
use Teazee\Model\ZoneInfo;
15
use Teazee\Model\ZoneInfoFactory;
16
17
/**
18
 * @author Michael Crumm <[email protected]>
19
 */
20
abstract class AbstractProvider implements Provider
21
{
22
    /**
23
     * @var ZoneInfoFactory
24
     */
25
    private $factory;
26
27
    /**
28
     * AbstractProvider Constructor.
29
     */
30
    public function __construct()
31
    {
32 22
        $this->factory = new ZoneInfoFactory();
33
    }
34
35
    /**
36
     * Returns the current time as seconds since January 1, 1970 UTC.
37
     *
38
     * @return int
39
     */
40
    protected function getCurrentTimestamp()
41
    {
42
        return (new DateTimeImmutable(null, new DateTimeZone('UTC')))->getTimestamp();
43
    }
44
45
    /**
46
     * Returns the default values for creating ZoneInfo.
47
     *
48
     * @return array
49
     */
50
    protected function getDefaults()
51
    {
52
        return [
53
            'dst'       => null,
54
            'id'        => null,
55
            'timestamp' => null,
56
            'utcOffset' => null,
57 11
        ];
58
    }
59
60
    /**
61
     * Creates ZoneInfo from the given parameters via the ZoneInfoFactory.
62
     *
63
     * @param array $data
64
     *
65
     * @return ZoneInfo
66
     */
67
    protected function returnResult(array $data)
68
    {
69 11
        return $this->factory->create($data);
70
    }
71
}
72