Completed
Push — master ( ec564d...deb061 )
by Robin
05:48
created

System::getNetPath()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 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 implements ISystem {
13
	private $smbclient;
14
15
	private $net;
16
17
	private $stdbuf;
18
19
	/**
20
	 * Get the path to a file descriptor of the current process
21
	 *
22
	 * @param int $num the file descriptor id
23
	 * @return string
24
	 * @throws Exception
25
	 */
26 777
	public function getFD($num) {
27
		$folders = [
28 777
			'/proc/self/fd',
29
			'/dev/fd'
30 259
		];
31 777
		foreach ($folders as $folder) {
32 777
			if (file_exists($folder)) {
33 777
				return $folder . '/' . $num;
34
			}
35
		}
36
		throw new Exception('Cant find file descriptor path');
37
	}
38
39 777
	public function getSmbclientPath() {
40 777
		if (!$this->smbclient) {
41 777
			$this->smbclient = trim(`which smbclient`);
42 259
		}
43 777
		return $this->smbclient;
44
	}
45
46 768
	public function getNetPath() {
47 768
		if (!$this->net) {
48 768
			$this->net = trim(`which net`);
49 256
		}
50 768
		return $this->net;
51
	}
52
53 765
	public function hasStdBuf() {
54 765
		if (!$this->stdbuf) {
55 765
			$result = null;
56 765
			$output = array();
57 765
			exec('which stdbuf 2>&1', $output, $result);
58 765
			$this->stdbuf = $result === 0;
59 255
		}
60 765
		return $this->stdbuf;
61
	}
62
}
63