Completed
Pull Request — master (#17)
by Janis
02:51
created

Application::__construct()   B

Complexity

Conditions 2
Paths 1

Size

Total Lines 85
Code Lines 43

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 44
CRAP Score 2.0023

Importance

Changes 0
Metric Value
dl 0
loc 85
ccs 44
cts 48
cp 0.9167
rs 8.6875
c 0
b 0
f 0
cc 2
eloc 43
nc 1
nop 1
crap 2.0023

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 2016
10
 */
11
12
namespace OCA\Ocr\AppInfo;
13
14
15
use OC\Files\View;
16
use OCA\Ocr\Controller\OcrController;
17
use OCA\Ocr\Db\OcrStatusMapper;
18
use OCA\Ocr\Service\OcrService;
19
use OCA\Ocr\Service\QueueService;
20
use OCP\AppFramework\App;
21
use OCP\AppFramework\IAppContainer;
22
use OCP\IContainer;
23
24
/**
25
 * Class Application
26
 *
27
 * @package OCA\Ocr\AppInfo
28
 */
29
class Application extends App {
30
	/**
31
	 * Application constructor.
32
	 *
33
	 * @param array $urlParams
34
	 */
35 5
	public function __construct(array $urlParams = array()) {
36 5
		parent::__construct('ocr', $urlParams);
37 5
		$container = $this->getContainer();
38
39
		/**
40
		 * Add the js and style if OCA\Files app is loaded
41
		 */
42 5
		$eventDispatcher = \OC::$server->getEventDispatcher();
43
		$eventDispatcher->addListener('OCA\Files::loadAdditionalScripts', function() {
44
			$scripts = array('ocrapp', 'ocrocr', 'ocrview');
45
			script('ocr', $scripts);
46
			style('ocr', 'style');
47 5
		});
48
49
		/**
50
		 * Register core services
51
		 */
52
		$container->registerService('CurrentUID', function(IContainer $c) {
53
			/** @var \OC\Server $server */
54 2
			$server = $c->query('ServerContainer');
55 2
			$user = $server->getUserSession()->getUser();
56 2
			return ($user) ? $user->getUID() : '';
57 5
		});
58
59
		// Allow automatic DI for the View, until they migrated to Nodes API
60
		$container->registerService(View::class, function() {
61
			return new View('');
62 5
		}, false);
63
64
		/**
65
		 * Register the Ocr Status mapper
66
		 */
67
		$container->registerService('OcrStatusMapper', function(IContainer $c) {
68
			/** @var \OC\Server $server */
69 4
			$server = $c->query('ServerContainer');
70 4
			return new OcrStatusMapper(
71 4
				$server->getDatabaseConnection()
72 4
			);
73 5
		});
74
75
		/**
76
		 * Register the Queue Service
77
		 */
78
		$container->registerService('QueueService', function(IAppContainer $c) {
79
			/** @var \OC\Server $server */
80 3
			$server = $c->query('ServerContainer');
81 3
			return new QueueService(
82 3
				$c->query('OcrStatusMapper'),
83 3
				$server->getL10N('ocr'),
84 3
				$server->getLogger()
85 3
			);
86 5
		});
87
88
		/**
89
		 * Register the Ocr Services
90
		 */
91
		$container->registerService('OcrService', function(IAppContainer $c) {
92
			/** @var \OC\Server $server */
93 2
			$server = $c->query('ServerContainer');
94 2
			return new OcrService(
95 2
				$server->getTempManager(),
96 2
				$server->getConfig(),
97 2
				$c->query('QueueService'),
98 2
				$c->query('OcrStatusMapper'),
99 2
				new View('/' . $c->query('CurrentUID') . '/files'),
100 2
				$c->query('CurrentUID'),
101 2
				$server->getL10N('ocr'),
102 2
				$server->getLogger()
103 2
			);
104 5
		});
105
106
		/**
107
		 * Controller
108
		 */
109 5
		$container->registerService('OcrController', function(IAppContainer $c) {
110
			/** @var \OC\Server $server */
111 1
			$server = $c->query('ServerContainer');
112 1
			return new OcrController(
113 1
				$c->getAppName(),
114 1
				$server->getRequest(),
115 1
				$c->query('OcrService'),
116 1
				$c->query('CurrentUID')
117 1
			);
118 5
		});
119 5
	}
120
121
}