Completed
Push — closes-181 ( cb5043...d1d34c )
by Victor
10:05
created

Socket::initScanner()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 12
ccs 0
cts 8
cp 0
rs 9.4285
cc 2
eloc 7
nc 2
nop 0
crap 6
1
<?php
2
/**
3
 * Copyright (c) 2017 Viktar Dubiniuk <[email protected]>
4
 * This file is licensed under the Affero General Public License version 3 or
5
 * later.
6
 * See the COPYING-README file.
7
 */
8
9
10
namespace OCA\Files_Antivirus\Scanner;
11
12
use OCA\Files_Antivirus\AppConfig;
13
use OCP\ILogger;
14
15
class Socket extends Daemon {
16
17 1
	public function __construct(AppConfig $config, ILogger $logger) {
18 1
		parent::__construct($config, $logger);
19
	}
20
21
	/
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected '/', expecting T_FUNCTION or T_CONST
Loading history...
22
	public function initScanner(){
23
		parent::initScanner();
24
		$this->writeHandle = stream_socket_client(
25
			'unix://' . $this->appConfig->getAvSocket(), $errorCode, $errorMessage, 5
26
		);
27
		if (!$this->getWriteHandle()) {
28
			throw new InitException(
29
				sprintf(
30
					'Could not connect to socket "%s": %s (code %d)',
31
					$this->appConfig->getAvSocket(),
32
					$errorMessage,
33
					$errorCode
34
				)
35
			);
36
		}
37
38
		if (@fwrite($this->getWriteHandle(), "nINSTREAM\n") === false) {
39
			throw new InitException(
40
				sprintf(
41
					'Writing to socket "%s" failed',
42
					$this->appConfig->getAvSocket()
43
				)
44
			);
45
		}
46
	}
47
}
48