Completed
Pull Request — master (#226)
by Victor
21:57 queued 20:26
created

Application::setupWrapper()   B

Complexity

Conditions 2
Paths 1

Size

Total Lines 30
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 2.0005

Importance

Changes 0
Metric Value
dl 0
loc 30
ccs 18
cts 19
cp 0.9474
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 20
nc 1
nop 0
crap 2.0005
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
use Symfony\Component\EventDispatcher\GenericEvent;
26
27
class Application extends App {
28 26
	public function __construct (array $urlParams = array()) {
29 26
		parent::__construct('files_antivirus', $urlParams);
30
		
31 26
		$container = $this->getContainer();
32 26
		$container->registerService(
33 26
			'RuleController',
34 26
			function ($c) {
35
				return new RuleController(
36
					$c->query('AppName'),
37
					$c->query('Request'),
38
					$c->query('Logger'),
39
					$c->query('L10N'),
40
					$c->query('RuleMapper')
41
				);
42 26
			}
43
		);
44 26
		$container->registerService(
45 26
			'SettingsController',
46 26
			function ($c) {
47
				return new SettingsController(
48
					$c->query('Request'),
49
					$c->query('AppConfig'),
50
					$c->query('ScannerFactory'),
51
					$c->query('L10N')
52
				);
53 26
			}
54
		);
55 26
		$container->registerService(
56 26
			'AppConfig',
57 26
			function ($c) {
58 6
				return new AppConfig(
59 6
					$c->query('CoreConfig')
60
				);
61 26
			}
62
		);
63
64 26
		$container->registerService(
65 26
			'ScannerFactory',
66 26
			function ($c) {
67 1
				return new ScannerFactory(
68 1
					$c->query('AppConfig'),
69 1
					$c->query('Logger')
70
				);
71 26
			}
72
		);
73
		
74 26
		$container->registerService(
75 26
			'BackgroundScanner',
76 26
			function ($c) {
77
				return new BackgroundScanner(
78
					$c->query('ScannerFactory'),
79
					$c->query('L10N'),
80
					$c->query('AppConfig'),
81
					$c->getServer()->getRootFolder(),
82
					$c->getServer()->getUserSession()
83
				);
84 26
			}
85
		);
86
87 26
		$container->registerService(
88 26
			'RuleMapper',
89 26
			function ($c) {
90
				return new RuleMapper(
91
					$c->query('ServerContainer')->getDb()
92
				);
93 26
			}
94
		);
95
96 26
		$container->registerService(
97 26
			'RequestHelper',
98 26
			function ($c) {
99 2
				return new RequestHelper(
100 2
					$c->query('ServerContainer')->getRequest()
101
				);
102 26
			}
103
		);
104
		
105
		/**
106
		 * Core
107
		 */
108 26
		$container->registerService(
109 26
			'Logger',
110 26
			function ($c) {
111 15
				return $c->query('ServerContainer')->getLogger();
112 26
			}
113
		);
114 26
		$container->registerService(
115 26
			'CoreConfig',
116 26
			function ($c) {
117 11
				return $c->query('ServerContainer')->getConfig();
118 26
			}
119
		);
120 26
		$container->registerService(
121 26
			'L10N',
122 26
			function ($c) {
123 1
				return $c->query('ServerContainer')->getL10N($c->query('AppName'));
124 26
			}
125
		);
126
127 26
		$dispatcher = $container->getServer()->getEventDispatcher();
128 26
		$dispatcher->addListener(
129 26
			'\OCA\Files_Antivirus\Dav\AntivirusPlugin::beforeMove',
130 26
			function (GenericEvent $event) use ($container) {
131
				$container->query('RequestHelper')->setSizeForPath(
132
					$event->getArgument('path'),
133
					$event->getArgument('finalSize')
134
				);
135 26
			}
136
		);
137 26
	}
138
	
139
	/**
140
	 * Add wrapper for local storages
141
	 *
142
	 * @return void
143
	 */
144 3
	public function setupWrapper() {
145 3
		\OC\Files\Filesystem::addStorageWrapper(
146 3
			'oc_avir',
147 3
			function ($mountPoint, $storage) {
148
				/**
149
				 * @var \OC\Files\Storage\Storage $storage
150
				 */
151 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...
152 3
					$appConfig = $this->getContainer()->query('AppConfig');
153 3
					$scannerFactory = $this->getContainer()->query('ScannerFactory');
154 3
					$l10n = $this->getContainer()->query('L10N');
155 3
					$logger = $this->getContainer()->query('Logger');
156 3
					$requestHelper = $this->getContainer()->query('RequestHelper');
157 3
					return new AvirWrapper(
158
						[
159 3
							'storage' => $storage,
160 3
							'appConfig' => $appConfig,
161 3
							'scannerFactory' => $scannerFactory,
162 3
							'l10n' => $l10n,
163 3
							'logger' => $logger,
164 3
							'requestHelper' => $requestHelper
165
						]
166
					);
167
				} else {
168
					return $storage;
169
				}
170 3
			},
171
			1
172
		);
173
	}
174
}
175