Completed
Push — master ( 50c9d0...db51c6 )
by Robin
06:58
created

TimeZoneProvider::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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