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

ScannerFactory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 68.42%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 34
ccs 13
cts 19
cp 0.6842
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getScanner() 0 19 5
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