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

TimeZoneProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 47
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 21 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 {
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 1044
	public function __construct($host, System $system) {
31 1044
		$this->host = $host;
32 1044
		$this->system = $system;
33 1044
	}
34
35 300
	public function get() {
36 300
		if (!$this->timeZone) {
37 300
			$net = $this->system->getNetPath();
38 300
			if ($net) {
39 292
				$command = sprintf('%s time zone -S %s',
40 292
					$net,
41 292
					escapeshellarg($this->host)
42 1
				);
43 292
				$this->timeZone = exec($command);
44 1
			}
45 300
			if (!$this->timeZone) { // fallback to server timezone
46 8
				$date = $this->system->getDatePath();
47 8
				if ($date) {
48 4
					$this->timeZone = exec($date . " +%z");
49 1
				} else {
50 4
					$this->timeZone = date_default_timezone_get();
51
				}
52 2
			}
53 3
		}
54 300
		return $this->timeZone;
55
	}
56
}
57