Completed
Push — stable3.0 ( bd43cd...55b7d1 )
by Robin
08:57 queued 07:06
created

NativeServer   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 57
ccs 20
cts 22
cp 0.9091
rs 10
c 0
b 0
f 0

5 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
A available() 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\Native;
9
10
use Icewind\SMB\AbstractServer;
11
use Icewind\SMB\IAuth;
12
use Icewind\SMB\System;
13
use Icewind\SMB\TimeZoneProvider;
14
15
class NativeServer extends AbstractServer {
16
	/**
17
	 * @var NativeState
18
	 */
19
	protected $state;
20
21
	/**
22
	 * @param string $host
23
	 * @param IAuth $auth
24
	 * @param System $system
25
	 * @param TimeZoneProvider $timeZoneProvider
26
	 */
27 255
	public function __construct($host, IAuth $auth, System $system, TimeZoneProvider $timeZoneProvider) {
28 255
		parent::__construct($host, $auth, $system, $timeZoneProvider);
29 255
		$this->state = new NativeState();
30 255
	}
31
32 1
	protected function connect() {
33 1
		$this->state->init($this->getAuth());
34 1
	}
35
36
	/**
37
	 * @return \Icewind\SMB\IShare[]
38
	 * @throws \Icewind\SMB\Exception\AuthenticationException
39
	 * @throws \Icewind\SMB\Exception\InvalidHostException
40
	 */
41 1
	public function listShares() {
42 1
		$this->connect();
43 1
		$shares = array();
44 1
		$dh = $this->state->opendir('smb://' . $this->getHost());
45 1
		while ($share = $this->state->readdir($dh)) {
46 1
			if ($share['type'] === 'file share') {
47 1
				$shares[] = $this->getShare($share['name']);
48 1
			}
49 1
		}
50 1
		$this->state->closedir($dh);
51 1
		return $shares;
52
	}
53
54
	/**
55
	 * @param string $name
56
	 * @return \Icewind\SMB\IShare
57
	 */
58 255
	public function getShare($name) {
59 255
		return new NativeShare($this, $name);
60
	}
61
62
	/**
63
	 * Check if the smbclient php extension is available
64
	 *
65
	 * @param System $system
66
	 * @return bool
67
	 */
68
	public static function available(System $system) {
69
		return function_exists('smbclient_state_new');
70
	}
71
}
72