Completed
Push — master ( 54efaa...464bdd )
by Janis
04:10
created

Application::__construct()   B

Complexity

Conditions 2
Paths 1

Size

Total Lines 117
Code Lines 56

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 58
CRAP Score 2.0019

Importance

Changes 0
Metric Value
dl 0
loc 117
ccs 58
cts 63
cp 0.9206
rs 8.2857
c 0
b 0
f 0
cc 2
eloc 56
nc 1
nop 1
crap 2.0019

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
 * nextCloud - ocr
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Janis Koehr <[email protected]>
9
 * @copyright Janis Koehr 2017
10
 */
11
12
namespace OCA\Ocr\AppInfo;
13
14
15
use OC\Files\View;
16
use OCA\Ocr\Controller\OcrController;
17
use OCA\Ocr\Controller\PersonalSettingsController;
18
use OCA\Ocr\Db\FileMapper;
19
use OCA\Ocr\Db\OcrStatusMapper;
20
use OCA\Ocr\Db\ShareMapper;
21
use OCA\Ocr\Service\OcrService;
22
use OCA\Ocr\Service\QueueService;
23
use OCP\AppFramework\App;
24
use OCP\AppFramework\IAppContainer;
25
use OCP\IContainer;
26
27
/**
28
 * Class Application
29
 *
30
 * @package OCA\Ocr\AppInfo
31
 */
32
class Application extends App {
33
	/**
34
	 * Application constructor.
35
	 *
36
	 * @param array $urlParams
37
	 */
38 8
	public function __construct(array $urlParams = array()) {
39 8
		parent::__construct('ocr', $urlParams);
40 8
		$container = $this->getContainer();
41
42
		/**
43
		 * Add the js and style if OCA\Files app is loaded
44
		 */
45 8
		$eventDispatcher = \OC::$server->getEventDispatcher();
46
		$eventDispatcher->addListener('OCA\Files::loadAdditionalScripts', function() {
47
			$scripts = array('ocrapp', 'ocrocr', 'ocrview');
48
			script('ocr', $scripts);
49
			style('ocr', 'ocrstyle');
50
			// if not loaded before - load select2 for multi select languages
51
			vendor_script('select2/select2');
52
			vendor_style('select2/select2');
53 8
		});
54
55
		/**
56
		 * Register core services
57
		 */
58
		$container->registerService('CurrentUID', function(IContainer $c) {
59
			/** @var \OC\Server $server */
60 2
			$server = $c->query('ServerContainer');
61 2
			$user = $server->getUserSession()->getUser();
62 2
			return ($user) ? $user->getUID() : '';
63 8
		});
64
65
		// Allow automatic DI for the View, until they migrated to Nodes API
66
		$container->registerService(View::class, function() {
67 1
			return new View('');
68 8
		}, false);
69
70
		/**
71
		 * Register the Ocr Status mapper
72
		 */
73
		$container->registerService('OcrStatusMapper', function(IContainer $c) {
74
			/** @var \OC\Server $server */
75 4
			$server = $c->query('ServerContainer');
76 4
			return new OcrStatusMapper(
77 4
				$server->getDatabaseConnection()
78 4
			);
79 8
		});
80
81
		/**
82
		 * Register the File mapper
83
		 */
84
		$container->registerService('FileMapper', function(IContainer $c) {
85
			/** @var \OC\Server $server */
86 3
			$server = $c->query('ServerContainer');
87 3
			return new FileMapper(
88 3
				$server->getDatabaseConnection()
89 3
			);
90 8
		});
91
92
		/**
93
		 * Register the Share mapper
94
		 */
95
		$container->registerService('ShareMapper', function(IContainer $c) {
96
			/** @var \OC\Server $server */
97 3
			$server = $c->query('ServerContainer');
98 3
			return new ShareMapper(
99 3
				$server->getDatabaseConnection()
100 3
			);
101 8
		});
102
103
		/**
104
		 * Register the Queue Service
105
		 */
106
		$container->registerService('QueueService', function(IAppContainer $c) {
107
			/** @var \OC\Server $server */
108 3
			$server = $c->query('ServerContainer');
109 3
			return new QueueService(
110 3
				$c->query('OcrStatusMapper'),
111 3
				$server->getConfig(),
112 3
				$server->getL10N('ocr'),
113 3
				$server->getLogger()
114 3
			);
115 8
		});
116
117
		/**
118
		 * Register the Ocr Services
119
		 */
120
		$container->registerService('OcrService', function(IAppContainer $c) {
121
			/** @var \OC\Server $server */
122 2
			$server = $c->query('ServerContainer');
123 2
			return new OcrService(
124 2
				$server->getTempManager(),
125 2
				$c->query('QueueService'),
126 2
				$c->query('OcrStatusMapper'),
127 2
				$c->query('FileMapper'),
128 2
				$c->query('ShareMapper'),
129 2
				new View('/' . $c->query('CurrentUID') . '/files'),
130 2
				$c->query('CurrentUID'),
131 2
				$server->getL10N('ocr'),
132 2
				$server->getLogger()
133 2
			);
134 8
		});
135
136
		/**
137
		 * Controller
138
		 */
139 8
		$container->registerService('OcrController', function(IAppContainer $c) {
140
			/** @var \OC\Server $server */
141 1
			$server = $c->query('ServerContainer');
142 1
			return new OcrController(
143 1
				$c->getAppName(),
144 8
				$server->getRequest(),
145 1
				$c->query('OcrService'),
146 1
				$c->query('CurrentUID')
147 1
			);
148 8
		});
149
150
		/**
151
		 * Controller
152
		 */
153 8
		$container->registerAlias('PersonalSettingsController', PersonalSettingsController::class);
154 8
	}
155
156
	/**
157
	 * Registers the Personal Settings Page for deletion of status objects and such things.
158
	 * @codeCoverageIgnore
159
	 */
160
	public function registerPersonal() {
161
		\OCP\App::registerPersonal($this->getContainer()->getAppName(), 'personal');
162
	}
163
164
}