Completed
Pull Request — master (#90)
by Janis
06:21
created

Application::__construct()   B

Complexity

Conditions 2
Paths 1

Size

Total Lines 116
Code Lines 55

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 52
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 116
ccs 52
cts 52
cp 1
rs 8.2857
c 0
b 0
f 0
cc 2
eloc 55
nc 1
nop 1
crap 2

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
			script('ocr', 'dist/ocrapp');
48
			style('ocr', 'ocrstyle');
49
			// if not loaded before - load select2 for multi select languages
50
			vendor_script('select2/select2');
51
			vendor_style('select2/select2');
52 8
		});
53
54
		/**
55
		 * Register core services
56
		 */
57
		$container->registerService('CurrentUID', function(IContainer $c) {
58
			/** @var \OC\Server $server */
59 2
			$server = $c->query('ServerContainer');
60 2
			$user = $server->getUserSession()->getUser();
61 2
			return ($user) ? $user->getUID() : '';
62 8
		});
63
64
		// Allow automatic DI for the View, until they migrated to Nodes API
65
		$container->registerService(View::class, function() {
66 1
			return new View('');
67 8
		}, false);
68
69
		/**
70
		 * Register the Ocr Status mapper
71
		 */
72
		$container->registerService('OcrStatusMapper', function(IContainer $c) {
73
			/** @var \OC\Server $server */
74 4
			$server = $c->query('ServerContainer');
75 4
			return new OcrStatusMapper(
76 4
				$server->getDatabaseConnection()
77
			);
78 8
		});
79
80
		/**
81
		 * Register the File mapper
82
		 */
83
		$container->registerService('FileMapper', function(IContainer $c) {
84
			/** @var \OC\Server $server */
85 3
			$server = $c->query('ServerContainer');
86 3
			return new FileMapper(
87 3
				$server->getDatabaseConnection()
88
			);
89 8
		});
90
91
		/**
92
		 * Register the Share mapper
93
		 */
94
		$container->registerService('ShareMapper', function(IContainer $c) {
95
			/** @var \OC\Server $server */
96 3
			$server = $c->query('ServerContainer');
97 3
			return new ShareMapper(
98 3
				$server->getDatabaseConnection()
99
			);
100 8
		});
101
102
		/**
103
		 * Register the Queue Service
104
		 */
105
		$container->registerService('QueueService', function(IAppContainer $c) {
106
			/** @var \OC\Server $server */
107 3
			$server = $c->query('ServerContainer');
108 3
			return new QueueService(
109 3
				$c->query('OcrStatusMapper'),
110 3
				$server->getConfig(),
111 3
				$server->getL10N('ocr'),
112 3
				$server->getLogger()
113
			);
114 8
		});
115
116
		/**
117
		 * Register the Ocr Services
118
		 */
119
		$container->registerService('OcrService', function(IAppContainer $c) {
120
			/** @var \OC\Server $server */
121 2
			$server = $c->query('ServerContainer');
122 2
			return new OcrService(
123 2
				$server->getTempManager(),
124 2
				$c->query('QueueService'),
125 2
				$c->query('OcrStatusMapper'),
126 2
				$c->query('FileMapper'),
127 2
				$c->query('ShareMapper'),
128 2
				new View('/' . $c->query('CurrentUID') . '/files'),
129 2
				$c->query('CurrentUID'),
130 2
				$server->getL10N('ocr'),
131 2
				$server->getLogger()
132
			);
133 8
		});
134
135
		/**
136
		 * Controller
137
		 */
138 8
		$container->registerService('OcrController', function(IAppContainer $c) {
139
			/** @var \OC\Server $server */
140 1
			$server = $c->query('ServerContainer');
141 1
			return new OcrController(
142 1
				$c->getAppName(),
143 1
				$server->getRequest(),
144 1
				$c->query('OcrService'),
145 1
				$c->query('CurrentUID')
146
			);
147 8
		});
148
149
		/**
150
		 * Controller
151
		 */
152 8
		$container->registerAlias('PersonalSettingsController', PersonalSettingsController::class);
153 8
	}
154
155
	/**
156
	 * Registers the Personal Settings Page for deletion of status objects and such things.
157
	 * @codeCoverageIgnore
158
	 */
159
	public function registerPersonal() {
160
		\OCP\App::registerPersonal($this->getContainer()->getAppName(), 'personal');
161
	}
162
163
}
164