Completed
Push — master ( 4fe26b...4d8bf0 )
by
unknown
03:55
created

Application   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 8

Test Coverage

Coverage 66.2%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 8
dl 0
loc 103
ccs 47
cts 71
cp 0.662
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 69 1
B setupWrapper() 0 28 2
1
<?php
2
/**
3
 * Copyright (c) 2015 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\AppInfo;
10
11
use \OCP\AppFramework\App;
12
13
use OCA\Files_Antivirus\AppConfig;
14
use OCA\Files_Antivirus\Controller\RuleController;
15
use OCA\Files_Antivirus\Controller\SettingsController;
16
use OCA\Files_Antivirus\Db\RuleMapper;
17
use OCA\Files_Antivirus\BackgroundScanner;
18
use OCA\Files_Antivirus\RequestHelper;
19
use OCA\Files_Antivirus\ScannerFactory;
20
21
use \OCA\Files_Antivirus\AvirWrapper;
22
23
class Application extends App {
24 21
	public function __construct (array $urlParams = array()) {
25 21
		parent::__construct('files_antivirus', $urlParams);
26
		
27 21
		$container = $this->getContainer();
28
		$container->registerService('RuleController', function($c) {
29
			return new RuleController(
30
				$c->query('AppName'),
31
				$c->query('Request'),
32
				$c->query('Logger'),
33
				$c->query('L10N'),
34
				$c->query('RuleMapper')
35
			);
36 21
		});
37
		$container->registerService('SettingsController', function($c) {
38
			return new SettingsController(
39
				$c->query('Request'),
40
				$c->query('AppConfig'),
41
				$c->query('ScannerFactory'),
42
				$c->query('L10N')	
43
			);
44 21
		});
45
		$container->registerService('AppConfig', function($c) {
46 7
			return new AppConfig(
47 7
				$c->query('CoreConfig')
48 7
			);
49 21
		});
50
		
51
        $container->registerService('ScannerFactory', function($c) {
52 1
			return new ScannerFactory(
53 1
				$c->query('AppConfig'),
54 1
				$c->query('Logger')
55 1
			);
56 21
        });
57
		
58
        $container->registerService('BackgroundScanner', function($c) {
59
			return new BackgroundScanner(
60
				$c->query('ScannerFactory'),
61
				$c->query('L10N'),
62
				$c->query('AppConfig'),
63
				$c->getServer()->getRootFolder(),
64
				$c->getServer()->getUserSession()
65
			);
66 21
		});
67
68
		$container->registerService('RuleMapper', function($c) {
69
			return new RuleMapper(
70
				$c->query('ServerContainer')->getDb()
71
			);
72 21
		});
73
74
		$container->registerService('RequestHelper', function($c) {
75 2
			return new RequestHelper(
76 2
				$c->query('ServerContainer')->getRequest()
77 2
			);
78 21
		});
79
		
80
		/**
81
		 * Core
82
		 */
83
		$container->registerService('Logger', function($c) {
84 15
			return $c->query('ServerContainer')->getLogger();
85 21
		});
86
        $container->registerService('CoreConfig', function($c) {
87 12
            return $c->query('ServerContainer')->getConfig();
88 21
        });
89
        $container->registerService('L10N', function($c) {
90 1
            return $c->query('ServerContainer')->getL10N($c->query('AppName'));
91 21
        });
92 21
	}
93
	
94
	/**
95
	 * Add wrapper for local storages
96
	 */
97 3
	public function setupWrapper(){
98 3
		\OC\Files\Filesystem::addStorageWrapper(
99 3
			'oc_avir',
100 3
			function ($mountPoint, $storage) {
101
				/**
102
				 * @var \OC\Files\Storage\Storage $storage
103
				 */
104 3
				if ($storage instanceof \OC\Files\Storage\Storage) {
0 ignored issues
show
Bug introduced by
The class OC\Files\Storage\Storage does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
105 3
					$appConfig = $this->getContainer()->query('AppConfig');
106 3
					$scannerFactory = $this->getContainer()->query('ScannerFactory');
107 3
					$l10n = $this->getContainer()->query('L10N');
108 3
					$logger = $this->getContainer()->query('Logger');
109 3
					$requestHelper = $this->getContainer()->query('RequestHelper');
110 3
					return new AvirWrapper([
111 3
						'storage' => $storage,
112 3
						'appConfig' => $appConfig,
113 3
						'scannerFactory' => $scannerFactory,
114 3
						'l10n' => $l10n,
115 3
						'logger' => $logger,
116
						'requestHelper' => $requestHelper
117 3
					]);
118
				} else {
119
					return $storage;
120
				}
121 3
			},
122
			1
123 3
		);
124 3
	}
125
}
126