Completed
Pull Request — master (#230)
by Victor
98:07 queued 91:44
created

Application::__construct()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 99
Code Lines 62

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 47
CRAP Score 1.0354

Importance

Changes 0
Metric Value
dl 0
loc 99
ccs 47
cts 70
cp 0.6714
rs 8.3103
c 0
b 0
f 0
cc 1
eloc 62
nc 1
nop 1
crap 1.0354

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
 * 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
			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
			}
44 26
		);
45 26
		$container->registerService(
46 26
			'SettingsController',
47
			function ($c) {
48
				return new SettingsController(
49
					$c->query('Request'),
50
					$c->query('AppConfig'),
51
					$c->query('ScannerFactory'),
52
					$c->query('L10N')
53
				);
54
			}
55 26
		);
56 26
		$container->registerService(
57 26
			'AppConfig',
58
			function ($c) {
59 7
				return new AppConfig(
60 7
					$c->query('CoreConfig')
61 7
				);
62
			}
63 26
		);
64
65 26
		$container->registerService(
66 26
			'ScannerFactory',
67
			function ($c) {
68 1
				return new ScannerFactory(
69 1
					$c->query('AppConfig'),
70 1
					$c->query('Logger')
71 1
				);
72
			}
73 26
		);
74
		
75 26
		$container->registerService(
76 26
			'BackgroundScanner',
77
			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
			}
86 26
		);
87
88 26
		$container->registerService(
89 26
			'RuleMapper',
90
			function ($c) {
91
				return new RuleMapper(
92
					$c->query('ServerContainer')->getDb()
93
				);
94
			}
95 26
		);
96
97 26
		$container->registerService(
98 26
			'RequestHelper',
99
			function ($c) {
100 2
				return new RequestHelper(
101 2
					$c->query('ServerContainer')->getRequest()
102 2
				);
103
			}
104 26
		);
105
		
106
		/**
107
		 * Core
108
		 */
109 26
		$container->registerService(
110 26
			'Logger',
111
			function ($c) {
112 15
				return $c->query('ServerContainer')->getLogger();
113
			}
114 26
		);
115 26
		$container->registerService(
116 26
			'CoreConfig',
117
			function ($c) {
118 12
				return $c->query('ServerContainer')->getConfig();
119
			}
120 26
		);
121 26
		$container->registerService(
122 26
			'L10N',
123
			function ($c) {
124 1
				return $c->query('ServerContainer')->getL10N($c->query('AppName'));
125
			}
126 26
		);
127 26
	}
128
	
129
	/**
130
	 * Add wrapper for local storages
131
	 *
132
	 * @return void
133
	 */
134 26
	public function setupWrapper() {
135 3
		\OC\Files\Filesystem::addStorageWrapper(
136 3
			'oc_avir',
137 26
			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 26
					$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
							'requestHelper' => $requestHelper
155 3
						]
156 3
					);
157
				} else {
158
					return $storage;
159
				}
160 3
			},
161
			1
162 3
		);
163 3
	}
164
}
165