Completed
Pull Request — master (#115)
by Thomas
05:40
created

Application::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 65
Code Lines 36

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 21
CRAP Score 1.1517

Importance

Changes 6
Bugs 2 Features 2
Metric Value
c 6
b 2
f 2
dl 0
loc 65
ccs 21
cts 45
cp 0.4667
rs 9.3571
cc 1
eloc 36
nc 1
nop 1
crap 1.1517

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
 * ownCloud - maps
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Sander Brand <[email protected]>
9
 * @copyright Sander Brand 2014
10
 */
11
12
namespace OCA\Maps\AppInfo;
13
14
15
use OC\AppFramework\Utility\SimpleContainer;
16
use \OCP\AppFramework\App;
17
use \OCA\Maps\Db\CacheManager;
18
use \OCA\Maps\Db\DeviceMapper;
19
use \OCA\Maps\Db\LocationMapper;
20
use \OCA\Maps\Db\FavoriteMapper;
21
use \OCA\Maps\Controller\PageController;
22
use \OCA\Maps\Controller\LocationController;
23
use \OCA\Maps\Controller\FavoriteController;
24
25
26
class Application extends App {
27
28
29 1
	public function __construct (array $urlParams=array()) {
30 1
		parent::__construct('maps', $urlParams);
31
32 1
		$container = $this->getContainer();
33
34
		/**
35
		 * Controllers
36
		 */
37
		$container->registerService('PageController', function($c) {
38
			/** @var SimpleContainer $c */
39 1
			return new PageController(
40 1
				$c->query('AppName'),
41 1
				$c->query('Request'),
42 1
				$c->query('UserId'),
43 1
				$c->query('CacheManager'),
44
				$c->query('DeviceMapper')
45
			);
46 1
		});
47
		$container->registerService('LocationController', function($c) {
48
			/** @var SimpleContainer $c */
49
			return new LocationController(
50
				$c->query('AppName'),
51
				$c->query('Request'),
52
				$c->query('LocationMapper'),
53
				$c->query('DeviceMapper'),
54
				$c->query('UserId')
55
			);
56 1
		});
57
		$container->registerService('FavoriteController', function($c) {
58
			/** @var SimpleContainer $c */
59
			return new FavoriteController(
60
				$c->query('AppName'),
61
				$c->query('Request'),
62
				$c->query('FavoriteMapper'),
63
				$c->query('UserId')
64
			);
65 1
		});
66
67 1
		$server = $container->getServer();
68
		$container->registerService('CacheManager', function($c) use ($server) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
69
			/** @var SimpleContainer $c */
70 1
			return new CacheManager(
71 1
				$server->getDatabaseConnection()
72 1
			);
73 1
		});
74
		$container->registerService('LocationMapper', function($c) use ($server) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
75
			/** @var SimpleContainer $c */
76
			return new LocationMapper(
77
				$server->getDb()
78
			);
79 1
		});
80
		$container->registerService('DeviceMapper', function($c) use ($server) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
81
			/** @var SimpleContainer $c */
82
			return new DeviceMapper(
83
				$server->getDb()
84
			);
85 1
		});
86 1
		$container->registerService('FavoriteMapper', function($c) use ($server) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
87
			/** @var SimpleContainer $c */
88
			return new FavoriteMapper(
89
				$server->getDb()
90
			);
91 1
		});
92
93 1
	}
94
95
96
}
97