AbstractScheduled   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 45
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getTimeZone() 0 8 2
B setTimeZone() 0 20 5
1
<?php
2
3
/*
4
 * janitor (http://juliangut.com/janitor).
5
 * Effortless maintenance management.
6
 *
7
 * @license BSD-3-Clause
8
 * @link https://github.com/juliangut/janitor
9
 * @author Julián Gutiérrez <[email protected]>
10
 */
11
12
namespace Janitor\Watcher;
13
14
/**
15
 * Abstract scheduled class.
16
 */
17
abstract class AbstractScheduled implements ScheduledWatcherInterface
18
{
19
    /**
20
     * Scheduled time zone.
21
     *
22
     * @var \DateTimeZone
23
     */
24
    protected $timeZone;
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function getTimeZone()
30
    {
31
        if ($this->timeZone === null) {
32
            $this->timeZone = new \DateTimeZone(date_default_timezone_get());
33
        }
34
35
        return $this->timeZone;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function setTimeZone($timeZone)
42
    {
43
        if (!$timeZone instanceof \DateTimeZone) {
44
            if (is_numeric($timeZone)) {
45
                $timeZoneName = timezone_name_from_abbr(null, $timeZone * 3600, true);
46
                if ($timeZoneName === false) {
47
                    throw new \InvalidArgumentException(sprintf('"%s" is not a valid time zone', $timeZone));
48
                }
49
                $timeZone = $timeZoneName;
50
            }
51
52
            try {
53
                $timeZone = new \DateTimeZone((string) $timeZone);
54
            } catch (\Exception $exception) {
55
                throw new \InvalidArgumentException(sprintf('"%s" is not a valid time zone', $timeZone));
56
            }
57
        }
58
59
        $this->timeZone = $timeZone;
60
    }
61
}
62