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

ScannerFactory::__construct()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 21
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 5.6359

Importance

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