Completed
Push — master ( eda387...29bdeb )
by Robin
04:14
created

TimeZoneProvider::get()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 3.004

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 15
ccs 12
cts 13
cp 0.9231
rs 9.4285
c 1
b 0
f 0
cc 3
eloc 11
nc 3
nop 0
crap 3.004
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 514
	public function __construct($host, System $system) {
31 514
		$this->host = $host;
32 514
		$this->system = $system;
33 514
	}
34
35 96
	public function get() {
36 96
		if (!$this->timeZone) {
37 96
			$net = $this->system->getNetPath();
38 96
			if ($net) {
39 96
				$command = sprintf('%s time zone -S %s',
40 96
					$net,
41 96
					escapeshellarg($this->host)
42 96
				);
43 96
				$this->timeZone = exec($command);
44 96
			} else { // fallback to server timezone
45
				$this->timeZone = date_default_timezone_get();
46
			}
47 96
		}
48 96
		return $this->timeZone;
49
	}
50
}
51