Completed
Push — master ( 89f47c...f4d8bc )
by Robin
03:18
created

TimeZoneProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 76.47%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 1
cbo 1
dl 0
loc 41
ccs 13
cts 17
cp 0.7647
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 15 3
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 1028
	public function __construct($host, System $system) {
31 1028
		$this->host = $host;
32 1028
		$this->system = $system;
33 1028
	}
34
35 192
	public function get() {
36 192
		if (!$this->timeZone) {
37 192
			$net = $this->system->getNetPath();
38 192
			if ($net) {
39 192
				$command = sprintf('%s time zone -S %s',
40 192
					$net,
41 192
					escapeshellarg($this->host)
42
				);
43 192
				$this->timeZone = exec($command);
44
			} else { // fallback to server timezone
45
				$this->timeZone = date_default_timezone_get();
46
			}
47
		}
48 192
		return $this->timeZone;
49
	}
50
}
51