Completed
Push — master ( ec564d...deb061 )
by Robin
05:48
created

TimeZoneProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 93.75%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 34
ccs 15
cts 16
cp 0.9375
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A get() 0 15 4
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 1032
	public function __construct(ISystem $system) {
25 1032
		$this->system = $system;
26 1032
	}
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 256
				);
36 768
				$this->timeZones[$host] = exec($command);
37 256
			} else { // fallback to server timezone
38
				$this->timeZones[$host] = date_default_timezone_get();
39
			}
40 256
		}
41 768
		return $this->timeZones[$host];
42
	}
43
}
44