External   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 29
ccs 12
cts 12
cp 1
rs 10
c 0
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
 * 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