Cancelled
Push — stable9 ( a5ea22...66c84e )
by Victor
516:53 queued 516:53
created

Application::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 66
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 22
CRAP Score 1

Importance

Changes 7
Bugs 3 Features 0
Metric Value
c 7
b 3
f 0
dl 0
loc 66
ccs 22
cts 22
cp 1
rs 9.3191
cc 1
eloc 40
nc 1
nop 1
crap 1

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 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
			);
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
			);
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 2
						'logger' => $logger
110
					]);
111
				} else {
112
					return $storage;
113
				}
114 2
			},
115 2
			1
116
		);
117 2
	}
118
}
119