Completed
Push — master ( 85c4a2...c508f5 )
by Roeland
16s queued 12s
created

ScannerFactory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 73.68%

Importance

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

2 Methods

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