Completed
Push — master ( 46dc92...267b49 )
by Victor
13s queued 11s
created

Application   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 137
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 8

Test Coverage

Coverage 78.26%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 8
dl 0
loc 137
ccs 72
cts 92
cp 0.7826
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 99 1
B setupWrapper() 0 30 2
1
<?php
2
/**
3
 * ownCloud - files_antivirus
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Viktar Dubiniuk <[email protected]>
9
 *
10
 * @copyright Viktar Dubiniuk 2014-2018
11
 * @license AGPL-3.0
12
 */
13
14
namespace OCA\Files_Antivirus\AppInfo;
15
16
use \OCP\AppFramework\App;
17
18
use OCA\Files_Antivirus\AppConfig;
19
use OCA\Files_Antivirus\Controller\RuleController;
20
use OCA\Files_Antivirus\Controller\SettingsController;
21
use OCA\Files_Antivirus\Db\RuleMapper;
22
use OCA\Files_Antivirus\BackgroundScanner;
23
use OCA\Files_Antivirus\RequestHelper;
24
use OCA\Files_Antivirus\ScannerFactory;
25
26
use \OCA\Files_Antivirus\AvirWrapper;
27
28
class Application extends App {
29 26
	public function __construct (array $urlParams = array()) {
30 26
		parent::__construct('files_antivirus', $urlParams);
31
		
32 26
		$container = $this->getContainer();
33 26
		$container->registerService(
34 26
			'RuleController',
35 26
			function ($c) {
36
				return new RuleController(
37
					$c->query('AppName'),
38
					$c->query('Request'),
39
					$c->query('Logger'),
40
					$c->query('L10N'),
41
					$c->query('RuleMapper')
42
				);
43 26
			}
44
		);
45 26
		$container->registerService(
46 26
			'SettingsController',
47 26
			function ($c) {
48
				return new SettingsController(
49
					$c->query('Request'),
50
					$c->query('AppConfig'),
51
					$c->query('ScannerFactory'),
52
					$c->query('L10N')
53
				);
54 26
			}
55
		);
56 26
		$container->registerService(
57 26
			'AppConfig',
58 26
			function ($c) {
59 7
				return new AppConfig(
60 7
					$c->query('CoreConfig')
61
				);
62 26
			}
63
		);
64
65 26
		$container->registerService(
66 26
			'ScannerFactory',
67 26
			function ($c) {
68 1
				return new ScannerFactory(
69 1
					$c->query('AppConfig'),
70 1
					$c->query('Logger')
71
				);
72 26
			}
73
		);
74
		
75 26
		$container->registerService(
76 26
			'BackgroundScanner',
77 26
			function ($c) {
78
				return new BackgroundScanner(
79
					$c->query('ScannerFactory'),
80
					$c->query('L10N'),
81
					$c->query('AppConfig'),
82
					$c->getServer()->getRootFolder(),
83
					$c->getServer()->getUserSession()
84
				);
85 26
			}
86
		);
87
88 26
		$container->registerService(
89 26
			'RuleMapper',
90 26
			function ($c) {
91
				return new RuleMapper(
92
					$c->query('ServerContainer')->getDb()
93
				);
94 26
			}
95
		);
96
97 26
		$container->registerService(
98 26
			'RequestHelper',
99 26
			function ($c) {
100 2
				return new RequestHelper(
101 2
					$c->query('ServerContainer')->getRequest()
102
				);
103 26
			}
104
		);
105
		
106
		/**
107
		 * Core
108
		 */
109 26
		$container->registerService(
110 26
			'Logger',
111 26
			function ($c) {
112 15
				return $c->query('ServerContainer')->getLogger();
113 26
			}
114
		);
115 26
		$container->registerService(
116 26
			'CoreConfig',
117 26
			function ($c) {
118 12
				return $c->query('ServerContainer')->getConfig();
119 26
			}
120
		);
121 26
		$container->registerService(
122 26
			'L10N',
123 26
			function ($c) {
124 1
				return $c->query('ServerContainer')->getL10N($c->query('AppName'));
125 26
			}
126
		);
127 26
	}
128
	
129
	/**
130
	 * Add wrapper for local storages
131
	 *
132
	 * @return void
133
	 */
134 3
	public function setupWrapper() {
135 3
		\OC\Files\Filesystem::addStorageWrapper(
136 3
			'oc_avir',
137 3
			function ($mountPoint, $storage) {
138
				/**
139
				 * @var \OC\Files\Storage\Storage $storage
140
				 */
141 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...
142 3
					$appConfig = $this->getContainer()->query('AppConfig');
143 3
					$scannerFactory = $this->getContainer()->query('ScannerFactory');
144 3
					$l10n = $this->getContainer()->query('L10N');
145 3
					$logger = $this->getContainer()->query('Logger');
146 3
					$requestHelper = $this->getContainer()->query('RequestHelper');
147 3
					return new AvirWrapper(
148
						[
149 3
							'storage' => $storage,
150 3
							'appConfig' => $appConfig,
151 3
							'scannerFactory' => $scannerFactory,
152 3
							'l10n' => $l10n,
153 3
							'logger' => $logger,
154 3
							'requestHelper' => $requestHelper
155
						]
156
					);
157
				} else {
158
					return $storage;
159
				}
160 3
			},
161
			1
162
		);
163
	}
164
}
165