Completed
Push — master ( de268f...fc9f0b )
by Robin
02:48
created

TimeZoneProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 38
ccs 15
cts 20
cp 0.75
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A get() 0 19 5
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 1039
	public function __construct(ISystem $system) {
25 1039
		$this->system = $system;
26 1039
	}
27
28 768
	public function get($host) {
29 768
		if (!isset($this->timeZones[$host])) {
30 768
			$net = $this->system->getNetPath();
31 768
			if ($net && $host) {
32 768
				$command = sprintf('%s time zone -S %s',
33 768
					$net,
34 768
					escapeshellarg($host)
35
				);
36 768
				$timeZone = exec($command);
37 768
				if (!$timeZone) {
38 3
					$timeZone = date_default_timezone_get();
39
				}
40 768
				$this->timeZones[$host] = $timeZone;
41
			} else { // fallback to server timezone
42
				$this->timeZones[$host] = date_default_timezone_get();
43
			}
44
		}
45 768
		return $this->timeZones[$host];
46
	}
47
}
48