Completed
Push — master ( b4a090...ed1dd0 )
by Roeland
10s
created

ScannerFactory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 73.68%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 47
ccs 14
cts 19
cp 0.7368
rs 10
c 2
b 0
f 0

2 Methods

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