Completed
Push — master ( 5fa6d3...7e7cc5 )
by
unknown
03:10
created

Application::__construct()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 99

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 44
CRAP Score 1.0274

Importance

Changes 0
Metric Value
dl 0
loc 99
ccs 44
cts 63
cp 0.6984
rs 8.0218
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1.0274

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