Completed
Pull Request — master (#195)
by Victor
19:38 queued 09:40
created

External::shutdownScanner()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1.0109

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 11
rs 9.4285
c 1
b 0
f 0
ccs 7
cts 9
cp 0.7778
cc 1
eloc 8
nc 1
nop 0
crap 1.0109
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
			'Response :: ' . $response,
22 2
			['app' => 'files_antivirus']
23 2
		);
24
		@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 2
26
		$this->status->parseResponse($response);
27
	}
28
29
	/**
30
	 * Prepend a chunk sent to ClamAv with its length
31
	 * @param string $data
32 2
	 * @return string
33 2
	 */
34 2
	protected function prepareChunk($data){
35 2
		$chunkLength = pack('N', strlen($data));
36
		return $chunkLength . $data;
37
	}
38
}
39