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

System   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 4
Dependencies 1

Test Coverage

Coverage 64.52%

Importance

Changes 0
Metric Value
wmc 11
lcom 4
cbo 1
dl 0
loc 53
ccs 20
cts 31
cp 0.6452
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getFD() 0 12 3
A getSmbclientPath() 0 6 2
A getNetPath() 0 6 2
A getDatePath() 0 6 2
A hasStdBuf() 0 9 2
1
<?php
2
/**
3
 * Copyright (c) 2014 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
use Icewind\SMB\Exception\Exception;
11
12
class System {
13
	private $smbclient;
14
15
	private $net;
16
17
	private $stdbuf;
18
19
	private $date;
20
21 777
	public static function getFD($num) {
22
		$folders = [
23 777
			'/proc/self/fd',
24
			'/dev/fd'
25
		];
26 777
		foreach ($folders as $folder) {
27 777
			if (file_exists($folder)) {
28 777
				return $folder . '/' . $num;
29
			}
30
		}
31
		throw new Exception('Cant find file descriptor path');
32
	}
33
34 777
	public function getSmbclientPath() {
35 777
		if (!$this->smbclient) {
36 777
			$this->smbclient = trim(`which smbclient`);
37
		}
38 777
		return $this->smbclient;
39
	}
40
41 288
	public function getNetPath() {
42 288
		if (!$this->net) {
43 288
			$this->net = trim(`which net`);
44
		}
45 288
		return $this->net;
46
	}
47
48
	public function getDatePath() {
49
		if (!$this->date) {
50
			$this->date = trim(`which date`);
51
		}
52
		return $this->date;
53
	}
54
55 765
	public function hasStdBuf() {
56 765
		if (!$this->stdbuf) {
57 765
			$result = null;
58 765
			$output = array();
59 765
			exec('which stdbuf 2>&1', $output, $result);
60 765
			$this->stdbuf = $result === 0;
61
		}
62 765
		return $this->stdbuf;
63
	}
64
}
65