Completed
Pull Request — master (#195)
by Victor
10:55 queued 09:43
created

Socket   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 23
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A initScanner() 0 20 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 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