Completed
Push — master ( d0f8dc...76d05f )
by Victor
14s
created

Application::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 69
Code Lines 42

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 24
CRAP Score 1.0862

Importance

Changes 0
Metric Value
dl 0
loc 69
ccs 24
cts 43
cp 0.5581
rs 9.2083
c 0
b 0
f 0
cc 1
eloc 42
nc 1
nop 1
crap 1.0862

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