Completed
Push — notifyhandler ( 1e7809...ebc1c0 )
by Robin
03:34
created

NativeServer::listShares()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3.054

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 12
ccs 9
cts 11
cp 0.8182
rs 9.4285
cc 3
eloc 9
nc 3
nop 0
crap 3.054
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
class NativeServer extends Server {
11
	/**
12
	 * @var \Icewind\SMB\NativeState
13
	 */
14
	protected $state;
15
16
	/**
17
	 * @param string $host
18
	 * @param string $user
19
	 * @param string $password
20
	 */
21 508
	public function __construct($host, $user, $password) {
22 508
		parent::__construct($host, $user, $password);
23 508
		$this->state = new NativeState();
24 508
	}
25
26 2
	protected function connect() {
27 2
		$this->state->init($this->getWorkgroup(), $this->getUser(), $this->getPassword());
28 2
	}
29
30
	/**
31
	 * @return \Icewind\SMB\IShare[]
32
	 * @throws \Icewind\SMB\Exception\AuthenticationException
33
	 * @throws \Icewind\SMB\Exception\InvalidHostException
34
	 */
35 2
	public function listShares() {
36 2
		$this->connect();
37 2
		$shares = array();
38 2
		$dh = $this->state->opendir('smb://' . $this->getHost());
39 2
		while ($share = $this->state->readdir($dh)) {
40 2
			if ($share['type'] === 'file share') {
41 2
				$shares[] = $this->getShare($share['name']);
42 2
			}
43 2
		}
44
		$this->state->closedir($dh);
45
		return $shares;
46
	}
47
48
	/**
49
	 * @param string $name
50
	 * @return \Icewind\SMB\IShare
51
	 */
52 508
	public function getShare($name) {
53 508
		return new NativeShare($this, $name);
54
	}
55
}
56