External::prepareChunk()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * ownCloud - Files_antivirus
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Viktar Dubiniuk <[email protected]>
9
 *
10
 * @copyright Viktar Dubiniuk 2017-2018
11
 * @license AGPL-3.0
12
 */
13
14
namespace OCA\Files_Antivirus\Scanner;
15
16
/**
17
 * Class External
18
 *
19
 * @package OCA\Files_Antivirus\Scanner
20
 */
21
abstract class External extends AbstractScanner {
22
	/**
23
	 * Send an empty chunk to indicate the end of stream,
24
	 * read response and close the handle
25
	 */
26 4
	protected function shutdownScanner() {
27 4
		@\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...
28 4
		$response = \fgets($this->getWriteHandle());
29 4
		$this->logger->debug(
30 4
			'Response :: ' . $response,
31 4
			['app' => 'files_antivirus']
32
		);
33 4
		@\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...
34
35 4
		$this->status->parseResponse($response);
36 4
	}
37
38
	/**
39
	 * Prepend a chunk sent to ClamAv with its length
40
	 *
41
	 * @param string $data
42
	 *
43
	 * @return string
44
	 */
45 4
	protected function prepareChunk($data) {
46 4
		$chunkLength = \pack('N', \strlen($data));
47 4
		return $chunkLength . $data;
48
	}
49
}
50