Passed
Push — master ( 8481d6...507b18 )
by Robin
03:14
created

NativeServer::available()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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\Native;
9
10
use Icewind\SMB\AbstractServer;
11
use Icewind\SMB\IAuth;
12
use Icewind\SMB\IOptions;
13
use Icewind\SMB\ISystem;
14
use Icewind\SMB\TimeZoneProvider;
15
16
class NativeServer extends AbstractServer {
17
	/**
18
	 * @var NativeState
19
	 */
20
	protected $state;
21
22 496
	public function __construct($host, IAuth $auth, ISystem $system, TimeZoneProvider $timeZoneProvider, IOptions $options) {
23 496
		parent::__construct($host, $auth, $system, $timeZoneProvider, $options);
24 496
		$this->state = new NativeState();
25 496
	}
26
27 2
	protected function connect() {
28 2
		$this->state->init($this->getAuth(), $this->getOptions());
29 2
	}
30
31
	/**
32
	 * @return \Icewind\SMB\IShare[]
33
	 * @throws \Icewind\SMB\Exception\AuthenticationException
34
	 * @throws \Icewind\SMB\Exception\InvalidHostException
35
	 */
36 2
	public function listShares() {
37 2
		$this->connect();
38 2
		$shares = [];
39 2
		$dh = $this->state->opendir('smb://' . $this->getHost());
40 2
		while ($share = $this->state->readdir($dh)) {
41 2
			if ($share['type'] === 'file share') {
42 2
				$shares[] = $this->getShare($share['name']);
43
			}
44
		}
45 2
		$this->state->closedir($dh);
46 2
		return $shares;
47
	}
48
49
	/**
50
	 * @param string $name
51
	 * @return \Icewind\SMB\IShare
52
	 */
53 494
	public function getShare($name) {
54 494
		return new NativeShare($this, $name);
55
	}
56
57
	/**
58
	 * Check if the smbclient php extension is available
59
	 *
60
	 * @param ISystem $system
61
	 * @return bool
62
	 */
63 6
	public static function available(ISystem $system) {
64 6
		return $system->libSmbclientAvailable();
65
	}
66
}
67