Completed
Push — prefer-dir ( c7f89d )
by Robin
12:57
created

TimeZoneProvider   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
B get() 0 20 6
1
<?php
2
/**
3
 * Copyright (c) 2015 Robin Appelman <[email protected]>
4
 * This file is licensed under the Licensed under the MIT license:
5
 * http://opensource.org/licenses/MIT
6
 */
7
8
namespace Icewind\SMB;
9
10
class TimeZoneProvider implements ITimeZoneProvider {
11
	/**
12
	 * @var string[]
13
	 */
14
	private $timeZones = [];
15
16
	/**
17
	 * @var ISystem
18
	 */
19
	private $system;
20
21
	/**
22
	 * @param ISystem $system
23
	 */
24
	public function __construct(ISystem $system) {
25
		$this->system = $system;
26
	}
27
28
	public function get($host) {
29
		if (!isset($this->timeZones[$host])) {
30
			$net = $this->system->getNetPath();
31
			// for local domain names we can assume same timezone
32
			if ($net && $host && strpos($host, '.') !== false) {
33
				$command = sprintf('%s time zone -S %s',
34
					$net,
35
					escapeshellarg($host)
36
				);
37
				$timeZone = exec($command);
38
				if (!$timeZone) {
39
					$timeZone = date_default_timezone_get();
40
				}
41
				$this->timeZones[$host] = $timeZone;
42
			} else { // fallback to server timezone
43
				$this->timeZones[$host] = date_default_timezone_get();
44
			}
45
		}
46
		return $this->timeZones[$host];
47
	}
48
}
49