Completed
Pull Request — master (#88)
by Julius
02:39
created

System   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 86.96%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 1
dl 0
loc 54
ccs 20
cts 23
cp 0.8696
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getSmbclientPath() 0 3 1
A getNetPath() 0 3 1
A getStdBufPath() 0 3 1
A getFD() 0 12 3
A getDatePath() 0 3 1
A libSmbclientAvailable() 0 3 1
A getBinaryPath() 0 9 3
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
	/** @var (string|bool)[] */
14
	private $paths = [];
15
16
	/**
17
	 * Get the path to a file descriptor of the current process
18
	 *
19
	 * @param int $num the file descriptor id
20
	 * @return string
21
	 * @throws Exception
22
	 */
23 1040
	public function getFD($num) {
24
		$folders = [
25 1040
			'/proc/self/fd',
26
			'/dev/fd'
27
		];
28 1040
		foreach ($folders as $folder) {
29 1040
			if (file_exists($folder)) {
30 1040
				return $folder . '/' . $num;
31
			}
32
		}
33
		throw new Exception('Cant find file descriptor path');
34
	}
35
36 1044
	public function getSmbclientPath() {
37 1044
		return $this->getBinaryPath('smbclient');
38
	}
39
40 1028
	public function getNetPath() {
41 1028
		return $this->getBinaryPath('net');
42
	}
43
44 1024
	public function getStdBufPath() {
45 1024
		return $this->getBinaryPath('stdbuf');
46
	}
47
48 1028
	public function getDatePath() {
49 1028
		return $this->getBinaryPath('date');
50
	}
51
52
	public function libSmbclientAvailable() {
53
		return function_exists('smbclient_state_new');
54
	}
55
56 1044
	protected function getBinaryPath($binary) {
57 1044
		if (!isset($this->paths[$binary])) {
58 1044
			$result = null;
59 1044
			$output = [];
60 1044
			exec("which $binary 2>&1", $output, $result);
61 1044
			$this->paths[$binary] = $result === 0 ? trim(implode('', $output)) : false;
62
		}
63 1044
		return $this->paths[$binary];
64
	}
65
}
66