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

System::getFD()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.1406

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 12
ccs 6
cts 8
cp 0.75
rs 9.4285
cc 3
eloc 8
nc 3
nop 1
crap 3.1406
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 259
	public static function getFD($num) {
20
		$folders = array(
21 259
			'/proc/self/fd',
22
			'/dev/fd'
23 259
		);
24 259
		foreach ($folders as $folder) {
25 259
			if (file_exists($folder)) {
26 259
				return $folder . '/' . $num;
27
			}
28
		}
29
		throw new Exception('Cant find file descriptor path');
30
	}
31
32 259
	public function getSmbclientPath() {
33 259
		if (!$this->smbclient) {
34 259
			$this->smbclient = trim(`which smbclient`);
35 259
		}
36 259
		return $this->smbclient;
37
	}
38
39 96
	public function getNetPath() {
40 96
		if (!$this->net) {
41 96
			$this->net = trim(`which net`);
42 96
		}
43 96
		return $this->net;
44
	}
45
46 255
	public function hasStdBuf() {
47 255
		if (!$this->stdbuf) {
48 255
			$result = null;
49 255
			$output = array();
50 255
			exec('which stdbuf 2>&1', $output, $result);
51 255
			$this->stdbuf = $result === 0;
52 255
		}
53 255
		return $this->stdbuf;
54
	}
55
}
56