Completed
Pull Request — master (#195)
by Victor
03:10
created

External   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 27
ccs 13
cts 13
cp 1
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A shutdownScanner() 0 11 1
A prepareChunk() 0 4 1
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
abstract class External extends AbstractScanner {
13
	/**
14
	 * Send an empty chunk to indicate the end of stream,
15
	 * read response and close the handle
16
	 */
17 2
	protected function shutdownScanner(){
18 2
		@fwrite($this->getWriteHandle(), pack('N', 0));
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...
19 2
		$response = fgets($this->getWriteHandle());
20 2
		$this->logger->debug(
21 2
			'Response :: ' . $response,
22 2
			['app' => 'files_antivirus']
23 2
		);
24 2
		@fclose($this->getWriteHandle());
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...
25
26 2
		$this->status->parseResponse($response);
27 2
	}
28
29
	/**
30
	 * Prepend a chunk sent to ClamAv with its length
31
	 * @param string $data
32
	 * @return string
33
	 */
34 2
	protected function prepareChunk($data){
35 2
		$chunkLength = pack('N', strlen($data));
36 2
		return $chunkLength . $data;
37
	}
38
}
39