Completed
Push — stable3.0 ( 04db6f...bd43cd )
by Robin
03:57
created

TimeZoneProvider::get()   B

Complexity

Conditions 6
Paths 7

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 19
cts 19
cp 1
rs 8.9457
c 0
b 0
f 0
cc 6
nc 7
nop 0
crap 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 {
11
	/**
12
	 * @var string
13
	 */
14
	private $host;
15
16
	/**
17
	 * @var string
18
	 */
19
	private $timeZone;
20
21
	/**
22
	 * @var System
23
	 */
24
	private $system;
25
26
	/**
27
	 * @param string $host
28
	 * @param System $system
29
	 */
30 1048
	public function __construct($host, System $system) {
31 1048
		$this->host = $host;
32 1048
		$this->system = $system;
33 1048
	}
34
35 436
	public function get() {
36 436
		if (!$this->timeZone) {
37 436
			$net = $this->system->getNetPath();
38
			// for local domain names we can assume same timezone
39 436
			if ($net && strpos($this->host, '.') !== false) {
40 4
				$command = sprintf('%s time zone -S %s',
41 4
					$net,
42 4
					escapeshellarg($this->host)
43 1
				);
44 4
				$this->timeZone = exec($command);
45 1
			}
46 436
			if (!$this->timeZone) { // fallback to server timezone
47 432
				$date = $this->system->getDatePath();
48 432
				if ($date) {
49 428
					$this->timeZone = exec($date . " +%z");
50 107
				} else {
51 4
					$this->timeZone = date_default_timezone_get();
52
				}
53 108
			}
54 109
		}
55 436
		return $this->timeZone;
56
	}
57
}
58