ConnectivityTester   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 31
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A canConnect() 0 11 2
1
<?php
2
3
/**
4
 * @author Christoph Wurst <[email protected]>
5
 *
6
 * Mail
7
 *
8
 * This code is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License, version 3,
10
 * as published by the Free Software Foundation.
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, version 3,
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
19
 *
20
 */
21
namespace OCA\Mail\Service\AutoConfig;
22
23
use OCA\Mail\Service\Logger;
24
25
abstract class ConnectivityTester {
26
27
	const CONNECTION_TIMEOUT = 10;
28
29
	/**
30
	 * @var Logger
31
	 */
32
	protected $logger;
33
34
	public function __construct(Logger $logger) {
35
		$this->logger = $logger;
36
	}
37
38
	/**
39
	 * @param string $url
40
	 * @param integer $port
41
	 * @return bool
42
	 */
43
	protected function canConnect($url, $port) {
44
		$this->logger->debug("attempting to connect to <$url> on port <$port>");
45
		$fp = fsockopen($url, $port, $error, $errorstr, self::CONNECTION_TIMEOUT);
46
		if (is_resource($fp)) {
47
			fclose($fp);
48
			$this->logger->debug("connection to <$url> on port <$port> established");
49
			return true;
50
		}
51
		$this->logger->debug("cannot connect to <$url> on port <$port>");
52
		return false;
53
	}
54
55
}
56