Completed
Push — master ( f4d8bc...afc829 )
by Robin
03:09
created

System::hasStdBuf()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

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