Completed
Push — notifyhandler ( ebc1c0...c1afd7 )
by Robin
04:14
created

NativeServer   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 46
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A connect() 0 3 1
A listShares() 0 12 3
A getShare() 0 3 1
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 2
		$this->state->closedir($dh);
45 2
		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