Completed
Pull Request — master (#195)
by Victor
14:02 queued 12:49
created

Socket::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
nc 1
cc 1
eloc 2
nop 1
crap 2
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 __construct($config){
15
		$this->appConfig = $config;
16
	}
17
18
	public function initScanner(){
19
		parent::initScanner();
20
21
		$this->writeHandle = stream_socket_client(
22
			'unix://' . $this->appConfig->getAvSocket(), $errorCode, $errorMessage, 5
23
		);
24
		if (!$this->getWriteHandle()) {
25
			throw new InitException(
26
				sprintf(
27
					'Could not connect to socket "%s": %s (code %d)',
28
					$this->appConfig->getAvSocket(),
29
					$errorMessage,
30
					$errorCode
31
				)
32
			);
33
		}
34
35
		// request scan from the daemon
36
		@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...
37
	}
38
}
39