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

Socket   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 1
cbo 3
dl 0
loc 27
ccs 0
cts 20
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
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 __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