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

External::initScanner()   B

Complexity

Conditions 6
Paths 10

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 7.6393

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 21
ccs 9
cts 14
cp 0.6429
rs 8.7624
cc 6
eloc 14
nc 10
nop 0
crap 7.6393

1 Method

Rating   Name   Duplication   Size   Complexity  
A External::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