Completed
Push — stable9 ( 66c84e...e336ce )
by Victor
7s
created

Application::setupWrapper()   B

Complexity

Conditions 2
Paths 1

Size

Total Lines 24
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 2.0008

Importance

Changes 5
Bugs 2 Features 1
Metric Value
c 5
b 2
f 1
dl 0
loc 24
ccs 16
cts 17
cp 0.9412
rs 8.9713
cc 2
eloc 16
nc 1
nop 0
crap 2.0008
1
<?php
2
/**
3
 * Copyright (c) 2015 Victor 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\Hooks\FilesystemHooks;
17
use OCA\Files_Antivirus\Db\RuleMapper;
18
use OCA\Files_Antivirus\BackgroundScanner;
19
use OCA\Files_Antivirus\ScannerFactory;
20
21
use \OCA\Files_Antivirus\AvirWrapper;
22
23
class Application extends App {
24 10
	public function __construct (array $urlParams = array()) {
25 10
		parent::__construct('files_antivirus', $urlParams);
26
		
27 10
		$container = $this->getContainer();
28
		$container->registerService('RuleController', function($c) {
29
			return new RuleController(
30
				$c->query('AppName'),
31
				$c->query('Request'),
32
				$c->query('Logger'),
33
				$c->query('L10N'),
34
				$c->query('RuleMapper')
35
			);
36 10
		});
37
		$container->registerService('SettingsController', function($c) {
38
			return new SettingsController(
39
				$c->query('Request'),
40
				$c->query('AppConfig'),
41
				$c->query('L10N')	
42
			);
43 10
		});
44
		$container->registerService('AppConfig', function($c) {
45 5
			return new AppConfig(
46 5
				$c->query('CoreConfig')
47 5
			);
48 10
		});
49
		
50
        $container->registerService('ScannerFactory', function($c) {
51 1
			return new ScannerFactory(
52 1
				$c->query('AppConfig'),
53 1
				$c->query('Logger')
54 1
			);
55 10
        });
56
		
57
        $container->registerService('BackgroundScanner', function($c) {
58
			return new BackgroundScanner(
59
				$c->query('ScannerFactory'),
60
				$c->query('ServerContainer')->getUserManager(),
61
				$c->query('L10N')
62
			);
63 10
        });
64
        $container->registerService('FilesystemHooks', function($c) {
65
			return new FilesystemHooks(
66
				$c->query('ServerContainer')->getRootFolder(),
67
				$c->query('AppConfig')
68
			);
69 10
        });
70
        $container->registerService('RuleMapper', function($c) {
71
			return new RuleMapper(
72
				$c->query('ServerContainer')->getDb()
73
			);
74 10
        });
75
		
76
		/**
77
		 * Core
78
		 */
79
		$container->registerService('Logger', function($c) {
80 4
			return $c->query('ServerContainer')->getLogger();
81 10
		});
82
        $container->registerService('CoreConfig', function($c) {
83 5
            return $c->query('ServerContainer')->getConfig();
84 10
        });
85
        $container->registerService('L10N', function($c) {
86 1
            return $c->query('ServerContainer')->getL10N($c->query('AppName'));
87 10
        });
88
		
89 10
	}
90
	
91
	/**
92
	 * Add wrapper for local storages
93
	 */
94 2
	public function setupWrapper(){
95 2
		\OC\Files\Filesystem::addStorageWrapper(
96 2
			'oc_avir',
97 2
			function ($mountPoint, $storage) {
98
				/**
99
				 * @var \OC\Files\Storage\Storage $storage
100
				 */
101 2
				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...
102 2
					$scannerFactory = $this->getContainer()->query('ScannerFactory');
103 2
					$l10n = $this->getContainer()->query('L10N');
104 2
					$logger = $this->getContainer()->query('Logger');
105 2
					return new AvirWrapper([
106 2
						'storage' => $storage,
107 2
						'scannerFactory' => $scannerFactory,
108 2
						'l10n' => $l10n,
109
						'logger' => $logger
110 2
					]);
111
				} else {
112
					return $storage;
113
				}
114 2
			},
115
			1
116 2
		);
117 2
	}
118
}
119