Completed
Push — master ( bebed6...b6e66d )
by Robin
02:58
created

TimeZoneProvider   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 47.62%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 40
ccs 10
cts 21
cp 0.4762
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
B get() 0 21 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 1044
	public function __construct(ISystem $system) {
25 1044
		$this->system = $system;
26 1044
	}
27
28 1024
	public function get($host) {
29 1024
		if (!isset($this->timeZones[$host])) {
30 1024
			$net = $this->system->getNetPath();
31
			// for local domain names we can assume same timezone
32 1024
			if ($net && $host && strpos($host, '.') !== false) {
33
				$command = sprintf(
34
					'%s time zone -S %s',
35
					$net,
36
					escapeshellarg($host)
37
				);
38
				$timeZone = exec($command);
39
				if (!$timeZone) {
40
					$timeZone = date_default_timezone_get();
41
				}
42
				$this->timeZones[$host] = $timeZone;
43
			} else { // fallback to server timezone
44 1024
				$this->timeZones[$host] = date_default_timezone_get();
45
			}
46 256
		}
47 1024
		return $this->timeZones[$host];
48
	}
49
}
50