Completed
Push — stable2 ( 4d0e89...3cf60d )
by Robin
07:27
created

System::getFD()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.1406

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 6
cts 8
cp 0.75
rs 9.8666
c 0
b 0
f 0
cc 3
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
	private $date;
20
21 1040
	public static function getFD($num) {
22
		$folders = array(
23 1040
			'/proc/self/fd',
24
			'/dev/fd'
25 780
		);
26 1040
		foreach ($folders as $folder) {
27 1040
			if (file_exists($folder)) {
28 1040
				return $folder . '/' . $num;
29
			}
30
		}
31
		throw new Exception('Cant find file descriptor path');
32
	}
33
34 1040
	public function getSmbclientPath() {
35 1040
		if (!$this->smbclient) {
36 1040
			$this->smbclient = trim(`which smbclient`);
37 780
		}
38 1040
		return $this->smbclient;
39
	}
40
41 424
	public function getNetPath() {
42 424
		if (!$this->net) {
43 424
			$this->net = trim(`which net`);
44 318
		}
45 424
		return $this->net;
46
	}
47
48 424
	public function getDatePath() {
49 424
		if (!$this->date) {
50 424
			$this->date = trim(`which date`);
51 318
		}
52 424
		return $this->date;
53
	}
54
55 1024
	public function hasStdBuf() {
56 1024
		if (!$this->stdbuf) {
57 1024
			$result = null;
58 1024
			$output = array();
59 1024
			exec('which stdbuf 2>&1', $output, $result);
60 1024
			$this->stdbuf = $result === 0;
61 768
		}
62 1024
		return $this->stdbuf;
63
	}
64
}
65