Skip to content

Commit

Permalink
chore: formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Sep 27, 2024
1 parent 3bfcc9a commit 7e14fa6
Show file tree
Hide file tree
Showing 26 changed files with 90 additions and 91 deletions.
2 changes: 1 addition & 1 deletion lib/BackgroundJob/BackgroundScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public function getUnscannedFiles() {
->andWhere($query->expr()->neq('mimetype', $query->createNamedParameter($dirMimeTypeId)))
->andWhere($query->expr()->orX(
$query->expr()->like('path', $query->createNamedParameter('files/%')),
$query->expr()->notLike('s.id', $query->createNamedParameter("home::%"))
$query->expr()->notLike('s.id', $query->createNamedParameter('home::%'))
))
->andWhere($this->getSizeLimitExpression($query))
->setMaxResults($this->getBatchSize() * 10);
Expand Down
4 changes: 2 additions & 2 deletions lib/Command/BackgroundScan.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected function configure() {
$this
->setName('files_antivirus:background-scan')
->setDescription('Run the background scan')
->addOption('max', 'm', InputOption::VALUE_REQUIRED, "Maximum number of files to process");
->addOption('max', 'm', InputOption::VALUE_REQUIRED, 'Maximum number of files to process');
}

protected function execute(InputInterface $input, OutputInterface $output): int {
Expand All @@ -61,7 +61,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$output->writeln("scanned <info>$count</info> files");
if ($count === $max) {
$output->writeln(" there might still be unscanned files remaining");
$output->writeln(' there might still be unscanned files remaining');
}

return 0;
Expand Down
6 changes: 3 additions & 3 deletions lib/Command/Mark.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ protected function configure() {
$this
->setName('files_antivirus:mark')
->setDescription('Mark a file as scanned or unscanned')
->addOption('forever', 'f', InputOption::VALUE_NONE, "When marking a file as scanned, set it to never rescan the file in the future")
->addArgument('file', InputArgument::REQUIRED, "Path of the file to mark")
->addArgument('mode', InputArgument::REQUIRED, "Either <info>scanned</info> or <info>unscanned</info>");
->addOption('forever', 'f', InputOption::VALUE_NONE, 'When marking a file as scanned, set it to never rescan the file in the future')
->addArgument('file', InputArgument::REQUIRED, 'Path of the file to mark')
->addArgument('mode', InputArgument::REQUIRED, 'Either <info>scanned</info> or <info>unscanned</info>');
}

protected function execute(InputInterface $input, OutputInterface $output): int {
Expand Down
14 changes: 7 additions & 7 deletions lib/Command/Scan.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ protected function configure() {
$this
->setName('files_antivirus:scan')
->setDescription('Scan a file')
->addArgument('file', InputArgument::REQUIRED, "Path of the file to scan")
->addOption('debug', null, InputOption::VALUE_NONE, "Enable debug output for supported backends");
->addArgument('file', InputArgument::REQUIRED, 'Path of the file to scan')
->addOption('debug', null, InputOption::VALUE_NONE, 'Enable debug output for supported backends');
}

protected function execute(InputInterface $input, OutputInterface $output): int {
Expand Down Expand Up @@ -73,22 +73,22 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$exit = 2;
break;
case \OCA\Files_Antivirus\Status::SCANRESULT_CLEAN:
$status = "is <info>clean</info>";
$status = 'is <info>clean</info>';
$exit = 0;
break;
case \OCA\Files_Antivirus\Status::SCANRESULT_INFECTED:
$status = "is <error>infected</error>";
$status = 'is <error>infected</error>';
$exit = 1;
break;
case \OCA\Files_Antivirus\Status::SCANRESULT_UNSCANNABLE:
$status = "is not scannable";
$status = 'is not scannable';
$exit = 2;
break;
}
if ($result->getDetails()) {
$details = ": " . $result->getDetails();
$details = ': ' . $result->getDetails();
} else {
$details = "";
$details = '';
}
$output->writeln("<info>$path</info> $status$details");

Expand Down
6 changes: 3 additions & 3 deletions lib/Command/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

$unscanned = $this->backgroundScanner->getUnscannedFiles();
$count = $this->processFiles($unscanned, $output, $verbose, "is unscanned");
$count = $this->processFiles($unscanned, $output, $verbose, 'is unscanned');
$output->writeln("$count unscanned files");

$rescan = $this->backgroundScanner->getToRescanFiles();
$count = $this->processFiles($rescan, $output, $verbose, "is scheduled for re-scan");
$count = $this->processFiles($rescan, $output, $verbose, 'is scheduled for re-scan');
$output->writeln("$count files scheduled for re-scan");

$outdated = $this->backgroundScanner->getOutdatedFiles();
$count = $this->processFiles($outdated, $output, $verbose, "has been updated");
$count = $this->processFiles($outdated, $output, $verbose, 'has been updated');
$output->writeln("$count have been updated since the last scan");

return 0;
Expand Down
32 changes: 16 additions & 16 deletions lib/Command/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,33 @@ protected function configure() {
$this
->setName('files_antivirus:test')
->setDescription('Test the availability of the configured scanner')
->addOption('debug', null, InputOption::VALUE_NONE, "Enable debug output for supported backends");
->addOption('debug', null, InputOption::VALUE_NONE, 'Enable debug output for supported backends');
}

protected function execute(InputInterface $input, OutputInterface $output): int {
$output->write("Scanning regular text: ");
$output->write('Scanning regular text: ');
$scanner = $this->scannerFactory->getScanner('/foo.txt');
if ($input->getOption('debug')) {
$output->writeln("");
$output->writeln('');
$scanner->setDebugCallback(function ($content) use ($output) {
$output->writeln($content);
});
}
$result = $scanner->scanString("dummy scan content");
$result = $scanner->scanString('dummy scan content');
if ($result->getNumericStatus() === Status::SCANRESULT_INFECTED) {
$details = $result->getDetails();
$output->writeln("<error>❌ $details</error>");
return 1;
} elseif ($result->getNumericStatus() === Status::SCANRESULT_UNCHECKED) {
$output->writeln("<comment>- file not scanned or scan still pending</comment>");
$output->writeln('<comment>- file not scanned or scan still pending</comment>');
} else {
$output->writeln("<info>✓</info>");
$output->writeln('<info>✓</info>');
}

$output->write("Scanning EICAR test file: ");
$output->write('Scanning EICAR test file: ');
$scanner = $this->scannerFactory->getScanner('/test-virus-eicar.txt');
if ($input->getOption('debug')) {
$output->writeln("");
$output->writeln('');
$scanner->setDebugCallback(function ($content) use ($output) {
$output->writeln($content);
});
Expand All @@ -78,19 +78,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln("<error>❌ file not detected $details</error>");
return 1;
} elseif ($result->getNumericStatus() === Status::SCANRESULT_UNCHECKED) {
$output->writeln("<comment>- file not scanned or scan still pending</comment>");
$output->writeln('<comment>- file not scanned or scan still pending</comment>');
} elseif ($result->getNumericStatus() === Status::SCANRESULT_UNSCANNABLE) {
$output->writeln("<comment>- file could not be scanned</comment>");
$output->writeln('<comment>- file could not be scanned</comment>');
} else {
$output->writeln("<info>✓</info>");
$output->writeln('<info>✓</info>');
}

// send a modified version of the EICAR because some scanners don't hold the scan request
// by default for files that haven't been seen before.
$output->write("Scanning modified EICAR test file: ");
$output->write('Scanning modified EICAR test file: ');
$scanner = $this->scannerFactory->getScanner('/test-virus-eicar-modified.txt');
if ($input->getOption('debug')) {
$output->writeln("");
$output->writeln('');
$scanner->setDebugCallback(function ($content) use ($output) {
$output->writeln($content);
});
Expand All @@ -101,11 +101,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln("<error>❌ file not detected $details</error>");
return 1;
} elseif ($result->getNumericStatus() === Status::SCANRESULT_UNCHECKED) {
$output->writeln("<comment>- file not scanned or scan still pending</comment>");
$output->writeln('<comment>- file not scanned or scan still pending</comment>');
} elseif ($result->getNumericStatus() === Status::SCANRESULT_UNSCANNABLE) {
$output->writeln("<comment>- file could not be scanned</comment>");
$output->writeln('<comment>- file could not be scanned</comment>');
} else {
$output->writeln("<info>✓</info>");
$output->writeln('<info>✓</info>');
}

return 0;
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function save(

try {
$scanner = $this->scannerFactory->getScanner('/self-test.txt');
$result = $scanner->scanString("dummy scan content");
$result = $scanner->scanString('dummy scan content');
$success = $result->getNumericStatus() == Status::SCANRESULT_CLEAN;
$message = $success ? $this->l10n->t('Saved') : 'unexpected scan results for test content';
} catch (\Exception $e) {
Expand Down
10 changes: 5 additions & 5 deletions lib/Db/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,35 +43,35 @@ class Rule extends Entity implements JsonSerializable {
/**
*
* @var int statusType - RULE_TYPE_CODE or RULE_TYPE_MATCH defines whether
* rule should be checked by the shell exit code or regexp
* rule should be checked by the shell exit code or regexp
*/
protected $statusType;

/**
*
* @var int result - shell exit code for rules
* of the type RULE_TYPE_CODE, 0 otherwise
* of the type RULE_TYPE_CODE, 0 otherwise
*/
protected $result;

/**
*
* @var string match - regexp to match for rules
* of the type RULE_TYPE_MATCH, '' otherwise
* of the type RULE_TYPE_MATCH, '' otherwise
*/
protected $match;

/**
*
* @var string description - shell exit code meaning for rules
* of the type RULE_TYPE_CODE, '' otherwise
* of the type RULE_TYPE_CODE, '' otherwise
*/
protected $description;

/**
*
* @var int status - file check status. SCANRESULT_UNCHECKED, SCANRESULT_INFECTED,
* SCANRESULT_CLEAN are matching Unknown, Infected and Clean files accordingly.
* SCANRESULT_CLEAN are matching Unknown, Infected and Clean files accordingly.
*/
protected $status;

Expand Down
4 changes: 2 additions & 2 deletions lib/ICAP/ICAPRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function __construct(
}

if ($this->responseCallback) {
($this->responseCallback)("ICAP Request headers:");
($this->responseCallback)('ICAP Request headers:');
($this->responseCallback)($request);
}

Expand All @@ -107,7 +107,7 @@ public function finish(): IcapResponse {
if ($this->responseCallback) {
$response = stream_get_contents($this->stream);

($this->responseCallback)("ICAP Response:");
($this->responseCallback)('ICAP Response:');
($this->responseCallback)($response);
$stream = fopen('php://temp', 'r+');
fwrite($stream, $response);
Expand Down
10 changes: 5 additions & 5 deletions lib/ICAP/ResponseParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ public function read_response($stream): IcapResponse {
private function readIcapStatusLine($stream): IcapResponseStatus {
$rawHeader = \fgets($stream);
if (!$rawHeader) {
throw new RuntimeException("Empty ICAP response");
throw new RuntimeException('Empty ICAP response');
}
$icapHeader = \trim($rawHeader);
$numValues = \sscanf($icapHeader, "ICAP/%d.%d %d %s", $v1, $v2, $code, $status);
$numValues = \sscanf($icapHeader, 'ICAP/%d.%d %d %s', $v1, $v2, $code, $status);
if ($numValues !== 4) {
throw new RuntimeException("Unknown ICAP response: \"$icapHeader\"");
}
Expand All @@ -52,9 +52,9 @@ private function readIcapStatusLine($stream): IcapResponseStatus {

private function parseEncapsulated(string $headerValue): array {
$result = [];
$encapsulatedParts = \explode(",", $headerValue);
$encapsulatedParts = \explode(',', $headerValue);
foreach ($encapsulatedParts as $encapsulatedPart) {
$pieces = \explode("=", \trim($encapsulatedPart));
$pieces = \explode('=', \trim($encapsulatedPart));
$result[$pieces[0]] = (int)$pieces[1];
}
return $result;
Expand Down Expand Up @@ -85,7 +85,7 @@ private function readHeaders($stream): array {
$headers = [];
while (($headerString = \fgets($stream)) !== false) {
$trimmedHeaderString = \trim($headerString);
if ($trimmedHeaderString === "") {
if ($trimmedHeaderString === '') {
break;
}
[$headerName, $headerValue] = $this->parseHeader($trimmedHeaderString);
Expand Down
2 changes: 1 addition & 1 deletion lib/Scanner/ExternalClam.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected function shutdownScanner() {

if ($info['timed_out']) {
$this->status->setNumericStatus(Status::SCANRESULT_UNCHECKED);
$this->status->setDetails("Socket timed out while scanning");
$this->status->setDetails('Socket timed out while scanning');
} else {
$this->status->parseResponse($response);
}
Expand Down
8 changes: 4 additions & 4 deletions lib/Scanner/ExternalKaspersky.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function initScanner() {
if (!($avHost && $avPort)) {
throw new \RuntimeException('The Kaspersky port and host are not set up.');
}
$this->writeHandle = fopen("php://temp", 'w+');
$this->writeHandle = fopen('php://temp', 'w+');
}

/**
Expand All @@ -51,7 +51,7 @@ public function initScanner() {
protected function writeChunk($chunk) {
if (ftell($this->writeHandle) > $this->chunkSize) {
$this->scanBuffer();
$this->writeHandle = fopen("php://temp", 'w+');
$this->writeHandle = fopen('php://temp', 'w+');
}
parent::writeChunk($chunk);
}
Expand All @@ -66,7 +66,7 @@ protected function scanBuffer(): void {
$body = base64_encode($body);
$response = $this->clientService->newClient()->post("$avHost:$avPort/api/v3.0/scanmemory", [
'json' => [
'timeout' => "60000",
'timeout' => '60000',
'object' => $body,
],
'connect_timeout' => 5,
Expand All @@ -92,7 +92,7 @@ protected function scanBuffer(): void {
$this->status->setDetails($scanResult);
} else {
$this->status->setNumericStatus(Status::SCANRESULT_INFECTED);
if (strpos($scanResult, "DETECT ") === 0) {
if (strpos($scanResult, 'DETECT ') === 0) {
$scanResult = substr($scanResult, 7);
}
if (isset($response['detectionName'])) {
Expand Down
18 changes: 9 additions & 9 deletions lib/Scanner/ICAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,31 +56,31 @@ public function __construct(

public function initScanner() {
parent::initScanner();
$this->writeHandle = fopen("php://temp", 'w+');
$this->writeHandle = fopen('php://temp', 'w+');
$path = '/' . trim($this->path, '/');
if (str_contains($path, '.ocTransferId') && str_ends_with($path, '.part')) {
[$path] = explode('.ocTransferId', $path, 2);
}
$remote = $this->request ? $this->request->getRemoteAddress() : null;
$encodedPath = implode("/", array_map("rawurlencode", explode("/", $path)));
$encodedPath = implode('/', array_map('rawurlencode', explode('/', $path)));
if ($this->mode === ICAPClient::MODE_REQ_MOD) {
$this->icapRequest = $this->icapClient->reqmod($this->service, [
'Allow' => 204,
"X-Client-IP" => $remote,
'X-Client-IP' => $remote,
], [
"PUT $encodedPath HTTP/1.0",
"Host: nextcloud"
'Host: nextcloud'
]);
} else {
$this->icapRequest = $this->icapClient->respmod($this->service, [
'Allow' => 204,
"X-Client-IP" => $remote,
'X-Client-IP' => $remote,
], [
"GET $encodedPath HTTP/1.0",
"Host: nextcloud",
'Host: nextcloud',
], [
"HTTP/1.0 200 OK",
"Content-Length: 1", // a dummy, non-zero, content length seems to be enough
'HTTP/1.0 200 OK',
'Content-Length: 1', // a dummy, non-zero, content length seems to be enough
]);
}
}
Expand All @@ -96,7 +96,7 @@ private function flushBuffer() {
rewind($this->writeHandle);
$data = stream_get_contents($this->writeHandle);
$this->icapRequest->write($data);
$this->writeHandle = fopen("php://temp", 'w+');
$this->writeHandle = fopen('php://temp', 'w+');
}

protected function scanBuffer() {
Expand Down
2 changes: 1 addition & 1 deletion lib/Scanner/ScannerBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ abstract class ScannerBase implements IScanner {

protected int $byteCount;

/** @var resource */
/** @var resource */
protected $writeHandle;

protected AppConfig $appConfig;
Expand Down
Loading

0 comments on commit 7e14fa6

Please sign in to comment.