Completed
Push — master ( 28c19e...a4e9ca )
by Joas
04:02
created

ScannerFactory::__construct()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 21
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 6.4704

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 21
ccs 11
cts 18
cp 0.6111
rs 8.7624
c 1
b 0
f 0
cc 5
eloc 18
nc 6
nop 2
crap 6.4704
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;
10
11
use \OCP\ILogger;
12
13
class ScannerFactory{
14
	
15
	/**
16
	 * @var \OCA\Files_Antivirus\AppConfig
17
	 */
18
	protected $appConfig;
19
	
20
	/**
21
	 * @var ILogger;
22
	 */
23
	protected $logger;
24
	
25
	/**
26
	 * @var string
27
	 */
28
	protected $scannerClass;
29
	
30 4
	public function __construct(AppConfig $appConfig, ILogger $logger){
31 4
			$this->appConfig = $appConfig;
32 4
			$this->logger = $logger;
33
			try {
34 4
				$avMode = $appConfig->getAvMode();
35
				switch($avMode) {
36 4
					case 'daemon':
37 4
					case 'socket':
38
						$this->scannerClass = 'OCA\Files_Antivirus\Scanner\External';
39
						break;
40 4
					case 'executable':
41 4
						$this->scannerClass = 'OCA\Files_Antivirus\Scanner\Local';
42 4
						break;
43
					default:
44
						$this->logger->warning('Application is misconfigured. Please check the settings at the admin page. Invalid mode: ' . $avMode);
45
						break;
46
				}
47 4
			} catch (\Exception $e){
48
				$logger->logException($e);
49
			}
50 4
	}
51
	
52
	/**
53
	 * Produce a scanner instance 
54
	 * @return \OCA\Files_Antivirus\Scanner
55
	 */
56 2
	public function getScanner(){
57 2
		return new $this->scannerClass($this->appConfig);
58
	}
59
}
60