Completed
Push — master ( ba7c5d...c3b626 )
by Julián
02:08
created

AbstractScheduled::setTimeZone()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 12
rs 9.2
cc 4
eloc 7
nc 3
nop 1
1
<?php
2
/**
3
 * Effortless maintenance management (http://juliangut.com/janitor)
4
 *
5
 * @link https://github.com/juliangut/janitor for the canonical source repository
6
 *
7
 * @license https://github.com/juliangut/janitor/blob/master/LICENSE
8
 */
9
10
namespace Janitor\Watcher\Scheduled;
11
12
use Janitor\ScheduledWatcher;
13
14
abstract class AbstractScheduled implements ScheduledWatcher
15
{
16
    /**
17
     * Scheduled time zone.
18
     *
19
     * @var \DateTimeZone
20
     */
21
    protected $timeZone;
22
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function getTimeZone()
27
    {
28
        if ($this->timeZone === null) {
29
            $this->timeZone = new \DateTimeZone(date_default_timezone_get());
30
        }
31
32
        return $this->timeZone;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function setTimeZone($timeZone = null)
39
    {
40
        if ($timeZone !== null && !$timeZone instanceof \DateTimeZone) {
41
            try {
42
                $timeZone = new \DateTimeZone($timeZone);
43
            } catch (\Exception $exception) {
44
                throw new \InvalidArgumentException(sprintf('"%s" is not a valid time zone', $timeZone));
45
            }
46
        }
47
48
        $this->timeZone = $timeZone;
49
    }
50
}
51