Completed
Push — master ( cd6579...b87b93 )
by
unknown
01:54
created

ScannerFactory::getScanner()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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 1
				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
	public function getScanner(){
58
		return new $this->scannerClass($this->appConfig, $this->logger, $this->statusFactory);
59
	}
60
}
61