Completed
Pull Request — master (#52)
by Roeland
02:11
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 5.7629

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 21
ccs 11
cts 16
cp 0.6875
rs 8.7624
nc 6
cc 5
eloc 18
nop 2
crap 5.7629
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