Completed
Push — master ( 55236a...de268f )
by Robin
16:10
created

ServerFactory::getSystem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * @copyright Copyright (c) 2018 Robin Appelman <[email protected]>
4
 *
5
 * @license GNU AGPL version 3 or any later version
6
 *
7
 * This program is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU Affero General Public License as
9
 * published by the Free Software Foundation, either version 3 of the
10
 * License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 *
20
 */
21
22
namespace Icewind\SMB;
23
24
25
use Icewind\SMB\Exception\DependencyException;
26
use Icewind\SMB\Native\NativeServer;
27
use Icewind\SMB\Wrapped\Server;
28
29
class ServerFactory {
30
	const BACKENDS = [
31
		NativeServer::class,
32
		Server::class
33
	];
34
35
	/** @var System */
36
	private $system;
37
38
	/** @var IOptions */
39
	private $options;
40
41
	/** @var ITimeZoneProvider */
42
	private $timeZoneProvider;
43
44
	/**
45
	 * ServerFactory constructor.
46
	 *
47
	 * @param IOptions|null $options
48
	 * @param ISystem|null $system
49
	 * @param ITimeZoneProvider|null $timeZoneProvider
50
	 */
51
	public function __construct(
52
		IOptions $options = null,
53
		ISystem $system = null,
54
		ITimeZoneProvider $timeZoneProvider = null
55
	) {
56
		if (is_null($options)) {
57
			$options = new Options();
58
		}
59
		if (is_null($system)) {
60
			$system = new System();
61
		}
62
		if (is_null($timeZoneProvider)) {
63
			$system = new TimeZoneProvider($system);
64
		}
65
		$this->options = $options;
66
		$this->system = $system;
0 ignored issues
show
Documentation Bug introduced by
It seems like $system of type object<Icewind\SMB\TimeZoneProvider> or object<Icewind\SMB\ISystem> is incompatible with the declared type object<Icewind\SMB\System> of property $system.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
67
	}
68
69
70
	/**
71
	 * @param $host
72
	 * @param IAuth $credentials
73
	 * @return IServer
74
	 * @throws DependencyException
75
	 */
76
	public function createServer($host, IAuth $credentials) {
77
		foreach (self::BACKENDS as $backend) {
78
			if (call_user_func("$backend::available", $this->system)) {
79
				return new $backend($host, $credentials, $this->system, $this->timeZoneProvider);
80
			}
81
		}
82
83
		throw new DependencyException('No valid backend available, ensure smbclient is in the path or php-smbclient is installed');
84
	}
85
}
86