Completed
Push — reformat ( 7da2f3 )
by Victor
05:31
created

Application::__construct()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 99
Code Lines 62

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 99
rs 8.3103
c 0
b 0
f 0
cc 1
eloc 62
nc 1
nop 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
	public function __construct (array $urlParams = array()) {
25
		parent::__construct('files_antivirus', $urlParams);
26
		
27
		$container = $this->getContainer();
28
		$container->registerService(
29
			'RuleController',
30
			function ($c) {
31
				return new RuleController(
32
					$c->query('AppName'),
33
					$c->query('Request'),
34
					$c->query('Logger'),
35
					$c->query('L10N'),
36
					$c->query('RuleMapper')
37
				);
38
			}
39
		);
40
		$container->registerService(
41
			'SettingsController',
42
			function ($c) {
43
				return new SettingsController(
44
					$c->query('Request'),
45
					$c->query('AppConfig'),
46
					$c->query('ScannerFactory'),
47
					$c->query('L10N')
48
				);
49
			}
50
		);
51
		$container->registerService(
52
			'AppConfig',
53
			function ($c) {
54
				return new AppConfig(
55
					$c->query('CoreConfig')
56
				);
57
			}
58
		);
59
60
		$container->registerService(
61
			'ScannerFactory',
62
			function ($c) {
63
				return new ScannerFactory(
64
					$c->query('AppConfig'),
65
					$c->query('Logger')
66
				);
67
			}
68
		);
69
		
70
		$container->registerService(
71
			'BackgroundScanner',
72
			function ($c) {
73
				return new BackgroundScanner(
74
					$c->query('ScannerFactory'),
75
					$c->query('L10N'),
76
					$c->query('AppConfig'),
77
					$c->getServer()->getRootFolder(),
78
					$c->getServer()->getUserSession()
79
				);
80
			}
81
		);
82
83
		$container->registerService(
84
			'RuleMapper',
85
			function ($c) {
86
				return new RuleMapper(
87
					$c->query('ServerContainer')->getDb()
88
				);
89
			}
90
		);
91
92
		$container->registerService(
93
			'RequestHelper',
94
			function ($c) {
95
				return new RequestHelper(
96
					$c->query('ServerContainer')->getRequest()
97
				);
98
			}
99
		);
100
		
101
		/**
102
		 * Core
103
		 */
104
		$container->registerService(
105
			'Logger',
106
			function ($c) {
107
				return $c->query('ServerContainer')->getLogger();
108
			}
109
		);
110
		$container->registerService(
111
			'CoreConfig',
112
			function ($c) {
113
				return $c->query('ServerContainer')->getConfig();
114
			}
115
		);
116
		$container->registerService(
117
			'L10N',
118
			function ($c) {
119
				return $c->query('ServerContainer')->getL10N($c->query('AppName'));
120
			}
121
		);
122
	}
123
	
124
	/**
125
	 * Add wrapper for local storages
126
	 *
127
	 * @return void
128
	 */
129
	public function setupWrapper() {
130
		\OC\Files\Filesystem::addStorageWrapper(
131
			'oc_avir',
132
			function ($mountPoint, $storage) {
133
				/**
134
				 * @var \OC\Files\Storage\Storage $storage
135
				 */
136
				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...
137
					$appConfig = $this->getContainer()->query('AppConfig');
138
					$scannerFactory = $this->getContainer()->query('ScannerFactory');
139
					$l10n = $this->getContainer()->query('L10N');
140
					$logger = $this->getContainer()->query('Logger');
141
					$requestHelper = $this->getContainer()->query('RequestHelper');
142
					return new AvirWrapper(
143
						[
144
							'storage' => $storage,
145
							'appConfig' => $appConfig,
146
							'scannerFactory' => $scannerFactory,
147
							'l10n' => $l10n,
148
							'logger' => $logger,
149
							'requestHelper' => $requestHelper
150
						]
151
					);
152
				} else {
153
					return $storage;
154
				}
155
			},
156
			1
157
		);
158
	}
159
}
160