Cancelled
Push — stable9 ( a5ea22...66c84e )
by Victor
516:53 queued 516:53
created

ScannerFactory::getScanner()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 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;
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 4
						break;
46
				}
47
			} catch (\Exception $e){
48
				$message = 	implode(' ', [ __CLASS__, __METHOD__, $e->getMessage()]);
49
				$logger->warning($message);
50
			}
51 4
	}
52
	
53
	/**
54
	 * Produce a scanner instance 
55
	 * @return \OCA\Files_Antivirus\Scanner
56
	 */
57 3
	public function getScanner(){
58 3
		return new $this->scannerClass($this->appConfig);
59
	}
60
}
61