Completed
Push — master ( b32497...b91e8b )
by Roeland
16s queued 12s
created

ScannerFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
/**
3
 * Copyright (c) 2014 Victor 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
namespace OCA\Files_Antivirus\Scanner;
10
11
use OCA\Files_Antivirus\AppConfig;
12
use OCP\IServerContainer;
13
14
class ScannerFactory {
15
	protected $appConfig;
16
	private $serverContainer;
17
18 1
	public function __construct(AppConfig $appConfig, IServerContainer $serverContainer) {
19 1
		$this->appConfig = $appConfig;
20 1
		$this->serverContainer = $serverContainer;
21 1
	}
22
23
	/**
24
	 * Produce a scanner instance
25
	 *
26
	 * @return IScanner
27
	 */
28 1
	public function getScanner() {
29 1
		$avMode = $this->appConfig->getAvMode();
30 1
		switch ($avMode) {
31 1
			case 'daemon':
32 1
			case 'socket':
33
				$scannerClass = ExternalClam::class;
34
				break;
35 1
			case 'executable':
36 1
				$scannerClass = LocalClam::class;
37 1
				break;
38
			case 'kaspersky':
39
				$scannerClass = ExternalKaspersky::class;
40
				break;
41
			default:
42
				throw new \InvalidArgumentException('Application is misconfigured. Please check the settings at the admin page. Invalid mode: ' . $avMode);
43
		}
44
45 1
		return $this->serverContainer->query($scannerClass);
46
	}
47
}
48