Completed
Pull Request — master (#52)
by Roeland
02:11
created

ScannerFactory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 72.21%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
c 2
b 0
f 0
lcom 1
cbo 1
dl 0
loc 47
ccs 13
cts 18
cp 0.7221
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 21 5
A getScanner() 0 3 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\ILogger;
13
14
class ScannerFactory{
15
	
16
	/**
17
	 * @var AppConfig
18
	 */
19
	protected $appConfig;
20
	
21
	/**
22
	 * @var ILogger;
23
	 */
24
	protected $logger;
25
	
26
	/**
27
	 * @var string
28
	 */
29
	protected $scannerClass;
30
	
31 4
	public function __construct(AppConfig $appConfig, ILogger $logger){
32 4
			$this->appConfig = $appConfig;
33 4
			$this->logger = $logger;
34
			try {
35 4
				$avMode = $appConfig->getAvMode();
36
				switch($avMode) {
37 4
					case 'daemon':
38 4
					case 'socket':
39
						$this->scannerClass = External::class;
40
						break;
41 4
					case 'executable':
42 4
						$this->scannerClass = Local::class;
43 4
						break;
44
					default:
45
						$this->logger->warning('Application is misconfigured. Please check the settings at the admin page. Invalid mode: ' . $avMode);
46 4
						break;
47
				}
48
			} catch (\Exception $e){
49
				$logger->logException($e);
50
			}
51 4
	}
52
	
53
	/**
54
	 * Produce a scanner instance 
55
	 * @return ScannerBase
56
	 */
57 2
	public function getScanner(){
58 2
		return new $this->scannerClass($this->appConfig);
59
	}
60
}
61