Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/files_antivirus.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCôme Chilliet <91878298+come-nc@users.noreply.github.com>2022-10-02 00:16:14 +0300
committerGitHub <noreply@github.com>2022-10-02 00:16:14 +0300
commit1aa4eb69d0f1c0efc86e8a5bb1b47246d572ce19 (patch)
treeca2f02097e6800398f2bafc089fd53cddc9b3eab
parent72fd67d5b2fe56a88390751468c14a79bac192cf (diff)
parent5c3a3c53cfee0634390231f12b876015ec12c51b (diff)
Merge branch 'master' into update-master-versionupdate-master-version
Signed-off-by: Côme Chilliet <91878298+come-nc@users.noreply.github.com>
-rw-r--r--.github/workflows/icap.yml12
-rw-r--r--.github/workflows/kaspersky.yml10
-rw-r--r--.github/workflows/lint.yml8
-rw-r--r--.github/workflows/phpunit.yml10
-rw-r--r--.github/workflows/static-analysis.yml10
-rw-r--r--.php-cs-fixer.dist.php (renamed from .php_cs.dist)0
-rw-r--r--.tx/config9
-rw-r--r--appinfo/info.xml4
-rw-r--r--composer.json2
-rw-r--r--composer.lock26
-rw-r--r--lib/BackgroundJob/BackgroundScanner.php52
-rw-r--r--lib/Item.php56
-rw-r--r--lib/ItemFactory.php57
-rw-r--r--lib/Scanner/ExternalClam.php17
-rw-r--r--lib/Scanner/ExternalKaspersky.php10
-rw-r--r--lib/Scanner/ICAP.php20
-rw-r--r--lib/Scanner/LocalClam.php16
-rw-r--r--lib/Scanner/ScannerBase.php54
-rw-r--r--lib/Status.php17
-rw-r--r--lib/StatusFactory.php23
-rw-r--r--psalm.xml4
-rw-r--r--tests/AvirWrapperTest.php8
-rw-r--r--tests/Scanner/ExternalKasperskyTest.php4
-rw-r--r--tests/Scanner/ICAPTest.php4
-rw-r--r--tests/StatusTest.php4
25 files changed, 177 insertions, 260 deletions
diff --git a/.github/workflows/icap.yml b/.github/workflows/icap.yml
index 05d4a4b..87c941b 100644
--- a/.github/workflows/icap.yml
+++ b/.github/workflows/icap.yml
@@ -1,5 +1,11 @@
name: ICAP
-on: [ push, pull_request ]
+
+on:
+ pull_request:
+ push:
+ branches:
+ - master
+ - stable*
env:
APP_NAME: files_antivirus
@@ -12,7 +18,7 @@ jobs:
matrix:
php-versions: ['7.4']
databases: ['sqlite']
- server-versions: [ 'stable23' ]
+ server-versions: [ 'stable24' ]
name: icap-clmav
@@ -75,7 +81,7 @@ jobs:
matrix:
php-versions: ['7.4']
databases: ['sqlite']
- server-versions: [ 'stable23' ]
+ server-versions: [ 'stable24' ]
name: icap-kaspersky
diff --git a/.github/workflows/kaspersky.yml b/.github/workflows/kaspersky.yml
index 42e855c..3c96d16 100644
--- a/.github/workflows/kaspersky.yml
+++ b/.github/workflows/kaspersky.yml
@@ -1,5 +1,11 @@
name: Kaspersky
-on: [ push, pull_request ]
+
+on:
+ pull_request:
+ push:
+ branches:
+ - master
+ - stable*
env:
APP_NAME: files_antivirus
@@ -12,7 +18,7 @@ jobs:
matrix:
php-versions: ['7.4']
databases: ['sqlite']
- server-versions: [ 'stable23' ]
+ server-versions: [ 'stable24' ]
name: kaspersky
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
index 617f20e..29236db 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -12,14 +12,8 @@ jobs:
strategy:
matrix:
php-version: ['7.4', '8.0']
- ocp-version: ['^v21.0.0', '^v22.0.0', '^v23.0.0', 'dev-master']
+ ocp-version: ['^v24.0.0', 'dev-master']
include:
- - php-version: '7.3'
- ocp-version: '^v21.0.0'
- - php-version: '7.3'
- ocp-version: '^v22.0.0'
- - php-version: '7.3'
- ocp-version: '^v23.0.0'
- php-version: '8.1'
ocp-version: 'dev-master'
name: php${{ matrix.php-version }}-ocp-${{ matrix.ocp-version }} lint
diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml
index edf70f9..898a86f 100644
--- a/.github/workflows/phpunit.yml
+++ b/.github/workflows/phpunit.yml
@@ -1,5 +1,11 @@
name: PHPUnit
-on: [push, pull_request]
+
+on:
+ pull_request:
+ push:
+ branches:
+ - master
+ - stable*
env:
APP_NAME: files_antivirus
@@ -14,7 +20,7 @@ jobs:
matrix:
php-versions: ['7.4']
databases: ['sqlite']
- server-versions: ['stable20', 'stable21', 'stable22', 'stable23', 'stable24', 'master']
+ server-versions: ['stable24', 'stable25', 'master']
name: php${{ matrix.php-versions }}-${{ matrix.databases }}-${{ matrix.server-versions }}
diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml
index b126721..aab106f 100644
--- a/.github/workflows/static-analysis.yml
+++ b/.github/workflows/static-analysis.yml
@@ -1,5 +1,11 @@
name: Php Static analysis
-on: [push, pull_request]
+
+on:
+ pull_request:
+ push:
+ branches:
+ - master
+ - stable*
jobs:
static-psalm-analysis:
@@ -7,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
- ocp-version: [ '20', '21', '22.0.0-RC1', '23.0.0-RC1', 'dev-master' ]
+ ocp-version: ['dev-stable24', 'dev-stable25', 'dev-master' ]
name: Nextcloud ${{ matrix.ocp-version }}
steps:
- name: Checkout
diff --git a/.php_cs.dist b/.php-cs-fixer.dist.php
index 5cb475d..5cb475d 100644
--- a/.php_cs.dist
+++ b/.php-cs-fixer.dist.php
diff --git a/.tx/config b/.tx/config
index f516a01..5dacebd 100644
--- a/.tx/config
+++ b/.tx/config
@@ -1,9 +1,10 @@
[main]
-host = https://www.transifex.com
-lang_map = bg_BG: bg, cs_CZ: cs, fi_FI: fi, hu_HU: hu, nb_NO: nb, sk_SK: sk, th_TH: th, ja_JP: ja
+host = https://www.transifex.com
+lang_map = ja_JP: ja, bg_BG: bg, cs_CZ: cs, fi_FI: fi, hu_HU: hu, nb_NO: nb, sk_SK: sk, th_TH: th
-[nextcloud.files_antivirus]
+[o:nextcloud:p:nextcloud:r:files_antivirus]
file_filter = translationfiles/<lang>/files_antivirus.po
source_file = translationfiles/templates/files_antivirus.pot
source_lang = en
-type = PO
+type = PO
+
diff --git a/appinfo/info.xml b/appinfo/info.xml
index ee05f5c..7c31641 100644
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -14,7 +14,7 @@
This application inspects files that are uploaded to Nextcloud for viruses before they are written to the Nextcloud storage. If a file is identified as a virus, it is either logged or not uploaded to the server. The application relies on the underlying ClamAV virus scanning engine, which the admin points Nextcloud to when configuring the application. Alternatively, a Kaspersky Scan Engine can be configured, which has to run on a separate server.
For this app to be effective, the ClamAV virus definitions should be kept up to date. Also note that enabling this app will impact system performance as additional processing is required for every upload. More information is available in the Antivirus documentation.
]]></description>
- <version>3.3.0</version>
+ <version>4.0.0</version>
<licence>agpl</licence>
<author>Manuel Delgado</author>
@@ -44,7 +44,7 @@ For this app to be effective, the ClamAV virus definitions should be kept up to
<screenshot>https://raw.githubusercontent.com/nextcloud/files_antivirus/master/screenshots/1.png</screenshot>
<dependencies>
- <nextcloud min-version="20" max-version="26" />
+ <nextcloud min-version="24" max-version="26" />
</dependencies>
<background-jobs>
diff --git a/composer.json b/composer.json
index b266a74..d8b3815 100644
--- a/composer.json
+++ b/composer.json
@@ -1,6 +1,6 @@
{
"require-dev": {
- "christophwurst/nextcloud": "^v20.0.0",
+ "christophwurst/nextcloud": "^v24.0.0",
"doctrine/dbal": "3.0.0",
"php-parallel-lint/php-parallel-lint": "^1.0",
"phpunit/phpunit": "^8",
diff --git a/composer.lock b/composer.lock
index 60b45ee..f7b0b41 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,34 +4,33 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "15f9da963d2a4afdd2b4d1137eb5eefc",
+ "content-hash": "1f50a47131b6aa8bad9f1d33f4219c3b",
"packages": [],
"packages-dev": [
{
"name": "christophwurst/nextcloud",
- "version": "dev-master",
+ "version": "v23.0.5",
"source": {
"type": "git",
"url": "https://github.com/ChristophWurst/nextcloud_composer.git",
- "reference": "a024da71102af8d9a0c4df9c9d27323f3f56ca84"
+ "reference": "2090802b05c9f8bffb2a7c02d6172571d4f90b90"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/ChristophWurst/nextcloud_composer/zipball/a024da71102af8d9a0c4df9c9d27323f3f56ca84",
- "reference": "a024da71102af8d9a0c4df9c9d27323f3f56ca84",
+ "url": "https://api.github.com/repos/ChristophWurst/nextcloud_composer/zipball/2090802b05c9f8bffb2a7c02d6172571d4f90b90",
+ "reference": "2090802b05c9f8bffb2a7c02d6172571d4f90b90",
"shasum": ""
},
"require": {
"php": "^7.3 || ~8.0.0",
- "psr/container": "^1.0",
+ "psr/container": "^1.1.1",
"psr/event-dispatcher": "^1.0",
"psr/log": "^1.1"
},
- "default-branch": true,
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "24.0.0-dev"
+ "dev-master": "23.0.0-dev"
}
},
"notification-url": "https://packagist.org/downloads/",
@@ -47,9 +46,10 @@
"description": "Composer package containing Nextcloud's public API (classes, interfaces)",
"support": {
"issues": "https://github.com/ChristophWurst/nextcloud_composer/issues",
- "source": "https://github.com/ChristophWurst/nextcloud_composer/tree/master"
+ "source": "https://github.com/ChristophWurst/nextcloud_composer/tree/v23.0.5"
},
- "time": "2021-12-17T01:13:06+00:00"
+ "abandoned": "nextcloud/ocp",
+ "time": "2022-06-02T14:19:33+00:00"
},
{
"name": "composer/package-versions-deprecated",
@@ -4930,12 +4930,10 @@
],
"aliases": [],
"minimum-stability": "stable",
- "stability-flags": {
- "christophwurst/nextcloud": 20
- },
+ "stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": [],
- "plugin-api-version": "2.1.0"
+ "plugin-api-version": "2.3.0"
}
diff --git a/lib/BackgroundJob/BackgroundScanner.php b/lib/BackgroundJob/BackgroundScanner.php
index 1e41e50..3023736 100644
--- a/lib/BackgroundJob/BackgroundScanner.php
+++ b/lib/BackgroundJob/BackgroundScanner.php
@@ -10,51 +10,35 @@ declare(strict_types=1);
namespace OCA\Files_Antivirus\BackgroundJob;
-use OC\BackgroundJob\TimedJob;
use OCA\Files_Antivirus\AppConfig;
use OCA\Files_Antivirus\ItemFactory;
use OCA\Files_Antivirus\Scanner\ScannerFactory;
+use OCP\BackgroundJob\TimedJob;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Files\File;
use OCP\Files\IMimeTypeLoader;
-use OCP\IDBConnection;
use OCP\Files\IRootFolder;
-use OCP\ILogger;
+use OCP\IDBConnection;
use OCP\IUser;
use OCP\IUserManager;
+use Psr\Log\LoggerInterface;
class BackgroundScanner extends TimedJob {
- /** @var IRootFolder */
- protected $rootFolder;
-
- /** @var ScannerFactory */
- private $scannerFactory;
-
- /** @var AppConfig */
- private $appConfig;
-
- /** @var ILogger */
- protected $logger;
-
- /** @var IUserManager */
- protected $userManager;
-
- /** @var IDBConnection */
- protected $db;
-
- /** @var IMimeTypeLoader */
- protected $mimeTypeLoader;
-
- /** @var ItemFactory */
- protected $itemFactory;
- /** @var bool */
- private $isCLI;
+ protected IRootFolder $rootFolder;
+ private ScannerFactory $scannerFactory;
+ private AppConfig $appConfig;
+ protected LoggerInterface $logger;
+ protected IUserManager $userManager;
+ protected IDBConnection $db;
+ protected IMimeTypeLoader $mimeTypeLoader;
+ protected ItemFactory $itemFactory;
+ private bool $isCLI;
public function __construct(
ScannerFactory $scannerFactory,
AppConfig $appConfig,
IRootFolder $rootFolder,
- ILogger $logger,
+ LoggerInterface $logger,
IUserManager $userManager,
IDBConnection $db,
IMimeTypeLoader $mimeTypeLoader,
@@ -78,7 +62,7 @@ class BackgroundScanner extends TimedJob {
/**
* Background scanner main job
*/
- public function run($args): void {
+ public function run($argument): void {
if ($this->appConfig->getAppValue('av_background_scan') !== 'on') {
// Background checking disabled no need to continue
$this->logger->debug('Antivirus background scan disablled, skipping');
@@ -89,7 +73,7 @@ class BackgroundScanner extends TimedJob {
try {
$result = $this->getUnscannedFiles();
} catch (\Exception $e) {
- $this->logger->logException($e);
+ $this->logger->error($e->getMessage(), ['exception' => $e]);
return;
}
@@ -131,7 +115,7 @@ class BackgroundScanner extends TimedJob {
break;
}
} catch (\Exception $e) {
- $this->logger->logException($e, ['app' => 'files_antivirus']);
+ $this->logger->error($e->getMessage(), ['exception' => $e]);
}
}
@@ -144,7 +128,7 @@ class BackgroundScanner extends TimedJob {
try {
$result = $this->getToRescanFiles();
} catch (\Exception $e) {
- $this->logger->logException($e);
+ $this->logger->error($e->getMessage(), ['exception' => $e]);
return;
}
@@ -191,7 +175,7 @@ class BackgroundScanner extends TimedJob {
try {
$result = $this->getOutdatedFiles();
} catch (\Exception $e) {
- $this->logger->logException($e);
+ $this->logger->error($e->getMessage(), ['exception' => $e]);
return;
}
diff --git a/lib/Item.php b/lib/Item.php
index a6da6c8..7a25c09 100644
--- a/lib/Item.php
+++ b/lib/Item.php
@@ -1,4 +1,7 @@
<?php
+
+declare(strict_types=1);
+
/**
* Copyright (c) 2015 Victor Dubiniuk <victor.dubiniuk@gmail.com>
* This file is licensed under the Affero General Public License version 3 or
@@ -11,13 +14,13 @@ namespace OCA\Files_Antivirus;
use OCA\Files_Antivirus\Activity\Provider;
use OCA\Files_Antivirus\AppInfo\Application;
use OCA\Files_Antivirus\Db\ItemMapper;
+use OCA\Files_Trashbin\Trash\ITrashManager;
use OCP\Activity\IManager as ActivityManager;
-use OCP\App;
use OCP\AppFramework\Db\DoesNotExistException;
+use OCP\App\IAppManager;
use OCP\Files\File;
use OCP\Files\IRootFolder;
-use OCA\Files_Trashbin\Trash\ITrashManager;
-use OCP\ILogger;
+use Psr\Log\LoggerInterface;
class Item {
/**
@@ -27,44 +30,27 @@ class Item {
*/
protected $fileHandle;
- /** @var AppConfig */
- private $config;
-
- /** @var ActivityManager */
- private $activityManager;
-
- /** @var ItemMapper */
- private $itemMapper;
-
- /** @var ILogger */
- private $logger;
-
- /** @var IRootFolder */
- private $rootFolder;
-
- /** @var File */
- private $file;
- private $isCron;
+ private AppConfig $config;
+ private ActivityManager $activityManager;
+ private ItemMapper $itemMapper;
+ private LoggerInterface $logger;
+ private IRootFolder $rootFolder;
+ private IAppManager $appManager;
+ private File $file;
+ private bool $isCron;
/**
* Item constructor.
- *
- * @param AppConfig $appConfig
- * @param ActivityManager $activityManager
- * @param ItemMapper $itemMapper
- * @param ILogger $logger
- * @param IRootFolder $rootFolder
- * @param File $file
- * @param bool $isCron
*/
public function __construct(
AppConfig $appConfig,
ActivityManager $activityManager,
ItemMapper $itemMapper,
- ILogger $logger,
+ LoggerInterface $logger,
IRootFolder $rootFolder,
+ IAppManager $appManager,
File $file,
- $isCron
+ bool $isCron
) {
$this->config = $appConfig;
$this->activityManager = $activityManager;
@@ -177,10 +163,8 @@ class Item {
/**
* Check if the end of file is reached
- *
- * @return boolean
*/
- private function feof() {
+ private function feof(): bool {
$isDone = feof($this->fileHandle);
if ($isDone) {
$this->logDebug('Scan is done');
@@ -213,13 +197,13 @@ class Item {
*/
private function deleteFile(): void {
//prevent from going to trashbin
- if (App::isEnabled('files_trashbin')) {
+ if ($this->appManager->isEnabledForUser('files_trashbin')) {
/** @var ITrashManager $trashManager */
$trashManager = \OC::$server->get(ITrashManager::class);
$trashManager->pauseTrash();
}
$this->file->delete();
- if (App::isEnabled('files_trashbin')) {
+ if ($this->appManager->isEnabledForUser('files_trashbin')) {
/** @var ITrashManager $trashManager */
$trashManager = \OC::$server->get(ITrashManager::class);
$trashManager->resumeTrash();
diff --git a/lib/ItemFactory.php b/lib/ItemFactory.php
index e2039a1..9eb7dde 100644
--- a/lib/ItemFactory.php
+++ b/lib/ItemFactory.php
@@ -1,8 +1,12 @@
<?php
+
+declare(strict_types=1);
+
/**
* @copyright Copyright (c) 2018 Roeland Jago Douma <roeland@famdouma.nl>
*
* @author Roeland Jago Douma <roeland@famdouma.nl>
+ * @author Côme Chilliet <come.chilliet@nextcloud.com>
*
* @license GNU AGPL version 3 or any later version
*
@@ -25,58 +29,43 @@ namespace OCA\Files_Antivirus;
use OCA\Files_Antivirus\Db\ItemMapper;
use OCP\Activity\IManager as ActivityManager;
+use OCP\App\IAppManager;
use OCP\Files\File;
use OCP\Files\IRootFolder;
-use OCP\ILogger;
+use Psr\Log\LoggerInterface;
class ItemFactory {
- /** @var AppConfig */
- private $config;
-
- /** @var ActivityManager */
- private $activityManager;
-
- /** @var ItemMapper */
- private $itemMapper;
-
- /** @var ILogger */
- private $logger;
-
- /** @var IRootFolder */
- private $rootFolder;
+ private AppConfig $config;
+ private ActivityManager $activityManager;
+ private ItemMapper $itemMapper;
+ private LoggerInterface $logger;
+ private IRootFolder $rootFolder;
+ private IAppManager $appManager;
- /**
- * ItemFactory constructor.
- *
- * @param AppConfig $appConfig
- * @param ActivityManager $activityManager
- * @param ItemMapper $itemMapper
- * @param ILogger $logger
- * @param IRootFolder $rootFolder
- */
- public function __construct(AppConfig $appConfig,
- ActivityManager $activityManager,
- ItemMapper $itemMapper,
- ILogger $logger,
- IRootFolder $rootFolder) {
+ public function __construct(
+ AppConfig $appConfig,
+ ActivityManager $activityManager,
+ ItemMapper $itemMapper,
+ LoggerInterface $logger,
+ IRootFolder $rootFolder,
+ IAppManager $appManager
+ ) {
$this->config = $appConfig;
$this->activityManager = $activityManager;
$this->itemMapper = $itemMapper;
$this->logger = $logger;
$this->rootFolder = $rootFolder;
+ $this->appManager = $appManager;
}
- /**
- * @param File $file
- * @return Item
- */
- public function newItem(File $file, $isCron = false) {
+ public function newItem(File $file, bool $isCron = false): Item {
return new Item(
$this->config,
$this->activityManager,
$this->itemMapper,
$this->logger,
$this->rootFolder,
+ $this->appManager,
$file,
$isCron
);
diff --git a/lib/Scanner/ExternalClam.php b/lib/Scanner/ExternalClam.php
index 6cf34bd..b9d4654 100644
--- a/lib/Scanner/ExternalClam.php
+++ b/lib/Scanner/ExternalClam.php
@@ -1,4 +1,7 @@
<?php
+
+declare(strict_types=1);
+
/**
* Copyright (c) 2014 Victor Dubiniuk <victor.dubiniuk@gmail.com>
* This file is licensed under the Affero General Public License version 3 or
@@ -11,24 +14,16 @@ namespace OCA\Files_Antivirus\Scanner;
use OCA\Files_Antivirus\AppConfig;
use OCA\Files_Antivirus\StatusFactory;
-use OCP\ILogger;
+use Psr\Log\LoggerInterface;
class ExternalClam extends ScannerBase {
/**
* Daemon/socket mode
- * @var bool
*/
- private $useSocket;
+ private bool $useSocket;
- /**
- * External constructor.
- *
- * @param AppConfig $config
- * @param ILogger $logger
- * @param StatusFactory $statusFactory
- */
- public function __construct(AppConfig $config, ILogger $logger, StatusFactory $statusFactory) {
+ public function __construct(AppConfig $config, LoggerInterface $logger, StatusFactory $statusFactory) {
parent::__construct($config, $logger, $statusFactory);
$this->useSocket = $this->appConfig->getAvMode() === 'socket';
}
diff --git a/lib/Scanner/ExternalKaspersky.php b/lib/Scanner/ExternalKaspersky.php
index 878bc9b..6b63e2e 100644
--- a/lib/Scanner/ExternalKaspersky.php
+++ b/lib/Scanner/ExternalKaspersky.php
@@ -1,6 +1,7 @@
<?php
declare(strict_types=1);
+
/**
* @copyright Copyright (c) 2020 Robin Appelman <robin@icewind.nl>
*
@@ -27,16 +28,15 @@ use OCA\Files_Antivirus\AppConfig;
use OCA\Files_Antivirus\Status;
use OCA\Files_Antivirus\StatusFactory;
use OCP\Http\Client\IClientService;
-use OCP\ILogger;
+use Psr\Log\LoggerInterface;
class ExternalKaspersky extends ScannerBase {
- /** @var IClientService IClientService */
- private $clientService;
- private $chunkSize;
+ private IClientService $clientService;
+ private int $chunkSize;
public function __construct(
AppConfig $config,
- ILogger $logger,
+ LoggerInterface $logger,
StatusFactory $statusFactory,
IClientService $clientService
) {
diff --git a/lib/Scanner/ICAP.php b/lib/Scanner/ICAP.php
index 2821076..7dae418 100644
--- a/lib/Scanner/ICAP.php
+++ b/lib/Scanner/ICAP.php
@@ -1,6 +1,7 @@
<?php
declare(strict_types=1);
+
/**
* @copyright Copyright (c) 2020 Robin Appelman <robin@icewind.nl>
*
@@ -28,23 +29,18 @@ use OCA\Files_Antivirus\ICAP\ICAPClient;
use OCA\Files_Antivirus\ICAP\ICAPRequest;
use OCA\Files_Antivirus\Status;
use OCA\Files_Antivirus\StatusFactory;
-use OCP\ILogger;
+use Psr\Log\LoggerInterface;
class ICAP extends ScannerBase {
- /** @var ICAPClient */
- private $icapClient;
- /** @var ?ICAPRequest */
- private $request;
- /** @var string */
- private $service;
- /** @var string */
- private $virusHeader;
- /** @var int */
- private $chunkSize;
+ private ICAPClient $icapClient;
+ private ?ICAPRequest $request;
+ private string $service;
+ private string $virusHeader;
+ private int $chunkSize;
public function __construct(
AppConfig $config,
- ILogger $logger,
+ LoggerInterface $logger,
StatusFactory $statusFactory
) {
parent::__construct($config, $logger, $statusFactory);
diff --git a/lib/Scanner/LocalClam.php b/lib/Scanner/LocalClam.php
index 2d314a9..5e04c1c 100644
--- a/lib/Scanner/LocalClam.php
+++ b/lib/Scanner/LocalClam.php
@@ -1,4 +1,7 @@
<?php
+
+declare(strict_types=1);
+
/**
* Copyright (c) 2014 Victor Dubiniuk <victor.dubiniuk@gmail.com>
* This file is licensed under the Affero General Public License version 3 or
@@ -6,25 +9,20 @@
* See the COPYING-README file.
*/
-
namespace OCA\Files_Antivirus\Scanner;
use OCA\Files_Antivirus\AppConfig;
use OCA\Files_Antivirus\StatusFactory;
-use OCP\ILogger;
+use Psr\Log\LoggerInterface;
class LocalClam extends ScannerBase {
-
- /**
- * @var string
- */
- protected $avPath;
+ protected string $avPath;
/**
* STDIN and STDOUT descriptors
* @var array of resources
*/
- private $pipes = [];
+ private array $pipes = [];
/**
* Process handle
@@ -32,7 +30,7 @@ class LocalClam extends ScannerBase {
*/
private $process;
- public function __construct(AppConfig $config, ILogger $logger, StatusFactory $statusFactory) {
+ public function __construct(AppConfig $config, LoggerInterface $logger, StatusFactory $statusFactory) {
parent::__construct($config, $logger, $statusFactory);
// get the path to the executable
diff --git a/lib/Scanner/ScannerBase.php b/lib/Scanner/ScannerBase.php
index d964266..2324c2b 100644
--- a/lib/Scanner/ScannerBase.php
+++ b/lib/Scanner/ScannerBase.php
@@ -27,60 +27,38 @@ use OCA\Files_Antivirus\AppConfig;
use OCA\Files_Antivirus\Item;
use OCA\Files_Antivirus\Status;
use OCA\Files_Antivirus\StatusFactory;
-use OCP\ILogger;
+use Psr\Log\LoggerInterface;
abstract class ScannerBase implements IScanner {
/**
* Scan result
- *
- * @var Status
*/
- protected $status;
+ protected Status $status;
/**
* If scanning was done part by part
* the first detected infected part is stored here
- *
- * @var Status
*/
- protected $infectedStatus;
+ protected ?Status $infectedStatus = null;
- /** @var int */
- protected $byteCount;
+ protected int $byteCount;
/** @var resource */
protected $writeHandle;
- /** @var AppConfig */
- protected $appConfig;
-
- /** @var ILogger */
- protected $logger;
-
- /** @var StatusFactory */
- protected $statusFactory;
-
- /** @var string */
- protected $lastChunk;
-
- /** @var bool */
- protected $isLogUsed = false;
-
- /** @var bool */
- protected $isAborted = false;
+ protected AppConfig $appConfig;
+ protected LoggerInterface $logger;
+ protected StatusFactory $statusFactory;
+ protected ?string $lastChunk = null;
+ protected bool $isLogUsed = false;
+ protected bool $isAborted = false;
- /**
- * ScannerBase constructor.
- *
- * @param AppConfig $config
- * @param ILogger $logger
- * @param StatusFactory $statusFactory
- */
- public function __construct(AppConfig $config, ILogger $logger, StatusFactory $statusFactory) {
+ public function __construct(AppConfig $config, LoggerInterface $logger, StatusFactory $statusFactory) {
$this->appConfig = $config;
$this->logger = $logger;
$this->statusFactory = $statusFactory;
+ $this->status = $this->statusFactory->newStatus();
}
/**
@@ -88,7 +66,6 @@ abstract class ScannerBase implements IScanner {
*/
abstract protected function shutdownScanner();
-
/**
* @return Status
*/
@@ -96,10 +73,7 @@ abstract class ScannerBase implements IScanner {
if ($this->infectedStatus instanceof Status) {
return $this->infectedStatus;
}
- if ($this->status instanceof Status) {
- return $this->status;
- }
- return $this->statusFactory->newStatus();
+ return $this->status;
}
/**
@@ -164,7 +138,7 @@ abstract class ScannerBase implements IScanner {
*/
public function initScanner() {
$this->byteCount = 0;
- if ($this->status instanceof Status && $this->status->getNumericStatus() === Status::SCANRESULT_INFECTED) {
+ if ($this->status->getNumericStatus() === Status::SCANRESULT_INFECTED) {
$this->infectedStatus = clone $this->status;
}
$this->status = $this->statusFactory->newStatus();
diff --git a/lib/Status.php b/lib/Status.php
index 688eb51..ce39b13 100644
--- a/lib/Status.php
+++ b/lib/Status.php
@@ -10,7 +10,7 @@ namespace OCA\Files_Antivirus;
use OCA\Files_Antivirus\Db\Rule;
use OCA\Files_Antivirus\Db\RuleMapper;
-use OCP\ILogger;
+use Psr\Log\LoggerInterface;
class Status {
@@ -39,19 +39,10 @@ class Status {
*/
protected $details = '';
- /** @var RuleMapper */
- protected $ruleMapper;
+ protected RuleMapper $ruleMapper;
+ protected LoggerInterface $logger;
- /** @var ILogger */
- protected $logger;
-
- /**
- * Status constructor.
- *
- * @param RuleMapper $ruleMapper
- * @param ILogger $logger
- */
- public function __construct(RuleMapper $ruleMapper, ILogger $logger) {
+ public function __construct(RuleMapper $ruleMapper, LoggerInterface $logger) {
$this->ruleMapper = $ruleMapper;
$this->logger = $logger;
}
diff --git a/lib/StatusFactory.php b/lib/StatusFactory.php
index 7f07d7c..94fe26f 100644
--- a/lib/StatusFactory.php
+++ b/lib/StatusFactory.php
@@ -24,31 +24,18 @@
namespace OCA\Files_Antivirus;
use OCA\Files_Antivirus\Db\RuleMapper;
-use OCP\ILogger;
+use Psr\Log\LoggerInterface;
class StatusFactory {
+ private RuleMapper $ruleMapper;
+ private LoggerInterface $logger;
- /** @var RuleMapper */
- private $ruleMapper;
-
- /** @var ILogger */
- private $logger;
-
- /**
- * StatusFactory constructor.
- *
- * @param RuleMapper $ruleMapper
- * @param ILogger $logger
- */
- public function __construct(RuleMapper $ruleMapper, ILogger $logger) {
+ public function __construct(RuleMapper $ruleMapper, LoggerInterface $logger) {
$this->ruleMapper = $ruleMapper;
$this->logger = $logger;
}
- /**
- * @return Status
- */
- public function newStatus() {
+ public function newStatus(): Status {
return new Status(
$this->ruleMapper,
$this->logger
diff --git a/psalm.xml b/psalm.xml
index 9eff8c8..9ec807d 100644
--- a/psalm.xml
+++ b/psalm.xml
@@ -4,10 +4,12 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config"
- phpVersion="7.3"
>
<projectFiles>
<directory name="lib"/>
+ <ignoreFiles>
+ <directory name="vendor" />
+ </ignoreFiles>
</projectFiles>
<extraFiles>
<directory name="vendor/christophwurst/nextcloud"/>
diff --git a/tests/AvirWrapperTest.php b/tests/AvirWrapperTest.php
index 84349a0..7343701 100644
--- a/tests/AvirWrapperTest.php
+++ b/tests/AvirWrapperTest.php
@@ -10,13 +10,13 @@
namespace OCA\Files_Antivirus\Tests;
-use OC\Files\Storage\Temporary;
use OCA\Files_Antivirus\AvirWrapper;
use OCA\Files_Antivirus\Scanner\ExternalClam;
use OCA\Files_Antivirus\Scanner\ScannerFactory;
use OCA\Files_Antivirus\StatusFactory;
use OCP\Activity\IManager;
-use OCP\ILogger;
+use OC\Files\Storage\Temporary;
+use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Test\Traits\UserTrait;
@@ -40,7 +40,7 @@ class AvirWrapperTest extends TestBase {
/** @var Temporary */
protected $storage;
- /** @var ILogger */
+ /** @var LoggerInterface */
protected $logger;
/** @var AvirWrapper */
@@ -51,7 +51,7 @@ class AvirWrapperTest extends TestBase {
$this->createUser(self::UID, self::PWD);
$this->storage = new Temporary([]);
- $this->logger = $this->createMock(ILogger::class);
+ $this->logger = $this->createMock(LoggerInterface::class);
$scanner = new ExternalClam(
$this->config,
diff --git a/tests/Scanner/ExternalKasperskyTest.php b/tests/Scanner/ExternalKasperskyTest.php
index 639a6cb..a570cee 100644
--- a/tests/Scanner/ExternalKasperskyTest.php
+++ b/tests/Scanner/ExternalKasperskyTest.php
@@ -28,7 +28,7 @@ use OCA\Files_Antivirus\Scanner\ExternalKaspersky;
use OCA\Files_Antivirus\Scanner\ScannerBase;
use OCA\Files_Antivirus\StatusFactory;
use OCP\Http\Client\IClientService;
-use OCP\ILogger;
+use Psr\Log\LoggerInterface;
/**
* @group DB
@@ -39,7 +39,7 @@ class ExternalKasperskyTest extends ScannerBaseTest {
$this->markTestSkipped("Set KASPERSKY_HOST and KASPERSKY_PORT to enable kaspersky tests");
}
- $logger = $this->createMock(ILogger::class);
+ $logger = $this->createMock(LoggerInterface::class);
$config = $this->createPartialMock(AppConfig::class, ['getter']);
$config->method('getter')
->willReturnCallback(function ($key) {
diff --git a/tests/Scanner/ICAPTest.php b/tests/Scanner/ICAPTest.php
index 13061cd..dfd7cca 100644
--- a/tests/Scanner/ICAPTest.php
+++ b/tests/Scanner/ICAPTest.php
@@ -27,7 +27,7 @@ use OCA\Files_Antivirus\AppConfig;
use OCA\Files_Antivirus\Scanner\ICAP;
use OCA\Files_Antivirus\Scanner\ScannerBase;
use OCA\Files_Antivirus\StatusFactory;
-use OCP\ILogger;
+use Psr\Log\LoggerInterface;
/**
* @group DB
@@ -38,7 +38,7 @@ class ICAPTest extends ScannerBaseTest {
$this->markTestSkipped("Set ICAP_HOST, ICAP_PORT, ICAP_REQUEST and ICAP_HEADER to enable icap tests");
}
- $logger = $this->createMock(ILogger::class);
+ $logger = $this->createMock(LoggerInterface::class);
$config = $this->createPartialMock(AppConfig::class, ['getter']);
$config->method('getter')
->willReturnCallback(function ($key) {
diff --git a/tests/StatusTest.php b/tests/StatusTest.php
index fa25daa..cf25352 100644
--- a/tests/StatusTest.php
+++ b/tests/StatusTest.php
@@ -9,7 +9,7 @@
namespace OCA\Files_Antivirus\Tests;
use \OCA\Files_Antivirus\Db\RuleMapper;
-use OCP\ILogger;
+use Psr\Log\LoggerInterface;
/**
* @group DB
@@ -35,7 +35,7 @@ class StatusTest extends TestBase {
// Testing status codes
$testStatus = new \OCA\Files_Antivirus\Status(
$this->ruleMapper,
- $this->createMock(ILogger::class)
+ $this->createMock(LoggerInterface::class)
);
$testStatus->parseResponse('dummy : OK', self::TEST_CLEAN);