DateFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 1
cbo 1
dl 0
loc 60
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A create() 0 4 1
A createNormalized() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of Gitamin.
5
 *
6
 * Copyright (C) 2015-2016 The Gitamin Team
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Gitamin\Dates;
13
14
use Jenssegers\Date\Date;
15
16
class DateFactory
17
{
18
    /**
19
     * The application timezone.
20
     *
21
     * @var string
22
     */
23
    protected $appTimezone;
24
25
    /**
26
     * The gitamin timezone.
27
     *
28
     * @var string
29
     */
30
    protected $gitaminTimezone;
31
32
    /**
33
     * Create a new date factory instance.
34
     *
35
     * @param string $appTimezone
36
     * @param string $gitaminTimezone
37
     */
38
    public function __construct($appTimezone, $gitaminTimezone)
39
    {
40
        $this->appTimezone = $appTimezone;
41
        $this->gitaminTimezone = $gitaminTimezone;
42
    }
43
44
    /**
45
     * Create a Carbon instance from a specific format.
46
     *
47
     * @param string $format
48
     * @param string $time
49
     *
50
     * @throws \InvalidArgumentException
51
     *
52
     * @return \Carbon\Carbon
53
     */
54
    public function create($format, $time)
55
    {
56
        return Date::createFromFormat($format, $time, $this->gitaminTimezone)->setTimezone($this->appTimezone);
57
    }
58
59
    /**
60
     * Create a Carbon instance from a specific format.
61
     *
62
     * We're also going to make sure the timezone information is correct.
63
     *
64
     * @param string $format
65
     * @param string $time
66
     *
67
     * @throws \InvalidArgumentException
68
     *
69
     * @return \Carbon\Carbon
70
     */
71
    public function createNormalized($format, $time)
72
    {
73
        return $this->create($format, $time)->setTimezone($this->appTimezone);
74
    }
75
}
76