Completed
Pull Request — stable9 (#144)
by Victor
02:22
created

Application   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Test Coverage

Coverage 62.9%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 7
dl 0
loc 93
ccs 39
cts 62
cp 0.629
rs 10
c 0
b 0
f 0

2 Methods

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