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

NativeServer   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 49
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getShare() 0 2 1
A available() 0 2 1
A listShares() 0 11 3
A connect() 0 2 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\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