Completed
Pull Request — master (#195)
by Victor
14:02 queued 12:49
created

ScannerFactory   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 68.18%

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 52
ccs 15
cts 22
cp 0.6818
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 26 6
A getScanner() 0 3 1
1
<?php
2
/**
3
 * Copyright (c) 2014 Viktar 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 OCA\Files_Antivirus\Scanner\InitException;
12
use \OCP\ILogger;
13
14
class ScannerFactory{
15
	
16
	/**
17
	 * @var \OCA\Files_Antivirus\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 8
	public function __construct(AppConfig $appConfig, ILogger $logger){
32 8
			$this->appConfig = $appConfig;
33 8
			$this->logger = $logger;
34
			try {
35 8
				$avMode = $appConfig->getAvMode();
36
				switch ($avMode) {
37 8
					case 'daemon':
38 4
						$this->scannerClass = 'OCA\Files_Antivirus\Scanner\Daemon';
39 4
						break;
40 5
					case 'socket':
41
						$this->scannerClass = 'OCA\Files_Antivirus\Scanner\Socket';
42
						break;
43 5
					case 'executable':
44 5
						$this->scannerClass = 'OCA\Files_Antivirus\Scanner\Local';
45 5
						break;
46
					default:
47
						$this->logger->warning('Application is misconfigured. Please check the settings at the admin page. Invalid mode: ' . $avMode);
48 8
						break;
49
				}
50
			} catch (InitException $e) {
51
				// TODO: add a new config option to prevent upload on misconfiguration
52
			} catch (\Exception $e) {
53
				$message = 	implode(' ', [ __CLASS__, __METHOD__, $e->getMessage()]);
54
				$this->logger->warning($message);
55
			}
56 8
	}
57
	
58
	/**
59
	 * Produce a scanner instance 
60
	 * @return \OCA\Files_Antivirus\Scanner\AbstractScanner
61
	 */
62 4
	public function getScanner(){
63 4
		return new $this->scannerClass($this->appConfig);
64
	}
65
}
66