Completed
Pull Request — master (#195)
by Victor
09:23 queued 08:01
created

Socket::initScanner()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 12

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 20
ccs 0
cts 17
cp 0
rs 9.4285
nc 2
cc 2
eloc 12
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
class Socket extends Daemon {
13
14
	public function initScanner(){
15
		parent::initScanner();
16
17
		$this->writeHandle = stream_socket_client(
18
			'unix://' . $this->appConfig->getAvSocket(), $errorCode, $errorMessage, 5
19
		);
20
		if (!$this->getWriteHandle()) {
21
			throw new InitException(
22
				sprintf(
23
					'Could not connect to socket "%s": %s (code %d)',
24
					$this->appConfig->getAvSocket(),
25
					$errorMessage,
26
					$errorCode
27
				)
28
			);
29
		}
30
31
		// request scan from the daemon
32
		@fwrite($this->getWriteHandle(), "nINSTREAM\n");
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
33
	}
34
}
35