Completed
Pull Request — master (#225)
by Victor
11:27 queued 09:57
created

Application::__construct()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 99
Code Lines 62

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 54
CRAP Score 1.0176

Importance

Changes 0
Metric Value
dl 0
loc 99
ccs 54
cts 73
cp 0.7397
rs 8.3103
c 0
b 0
f 0
cc 1
eloc 62
nc 1
nop 1
crap 1.0176

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