Completed
Push — fix_broken_js_unit_test-d6ae96... ( d6ae96 )
by Thomas
21:39
created

BackendFactory::createBackend()   B

Complexity

Conditions 5
Paths 1

Size

Total Lines 18
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 18
rs 8.8571
cc 5
eloc 14
nc 1
nop 9

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
/**
3
 * ownCloud - Calendar App
4
 *
5
 * @author Georg Ehrke
6
 * @copyright 2014 Georg Ehrke <[email protected]>
7
 *
8
 * This library is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
10
 * License as published by the Free Software Foundation; either
11
 * version 3 of the License, or any later version.
12
 *
13
 * This library is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public
19
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
20
 *
21
 */
22
namespace OCA\Calendar\Db;
23
24
use OCA\Calendar\IBackendCollection;
25
26
class BackendFactory { //TODO extend entity Factory
27
28
	/**
29
	 * @var callable
30
	 */
31
	private $defaultObjectCache;
32
33
34
	/**
35
	 * @var callable
36
	 */
37
	private $defaultObjectScanner;
38
39
40
	/**
41
	 * @var callable
42
	 */
43
	private $defaultObjectUpdater;
44
45
46
	/**
47
	 * @var callable
48
	 */
49
	private $defaultObjectWatcher;
50
51
52
	/**
53
	 * @param callable $objectCache
54
	 * @param callable $objectScanner
55
	 * @param callable $objectUpdater
56
	 * @param callable $objectWatcher
57
	 */
58
	public function __construct(callable $objectCache, callable $objectScanner,
59
								callable $objectUpdater, callable $objectWatcher) {
60
		$this->defaultObjectCache = $objectCache;
61
		$this->defaultObjectScanner = $objectScanner;
62
		$this->defaultObjectUpdater = $objectUpdater;
63
		$this->defaultObjectWatcher = $objectWatcher;
64
	}
65
66
67
	/**
68
	 * @param $id
69
	 * @param IBackendCollection $backends
70
	 * @param callable $backendAPI
71
	 * @param callable $calendarAPI
72
	 * @param callable $objectAPI
73
	 * @param callable $objectCache
74
	 * @param callable $objectScanner
75
	 * @param callable $objectUpdater
76
	 * @param callable $objectWatcher
77
	 *
78
	 * @return Backend
79
	 */
80
	public function createBackend($id, IBackendCollection $backends, callable $backendAPI, callable $calendarAPI,
81
								  callable $objectAPI, callable $objectCache = null, callable $objectScanner = null,
82
								  callable $objectUpdater = null, callable $objectWatcher = null) {
83
		$backend = new Backend();
84
		$backend->setId($id);
85
		$backend->setBackendAPI($backendAPI);
86
		$backend->setCalendarAPI($calendarAPI);
87
		$backend->setObjectAPI($objectAPI);
88
89
		$backend->setObjectcache(($objectCache) ? $objectCache : $this->defaultObjectCache);
90
		$backend->setObjectScanner(($objectScanner) ? $objectScanner : $this->defaultObjectScanner);
91
		$backend->setObjectUpdater(($objectUpdater) ? $objectUpdater : $this->defaultObjectUpdater);
92
		$backend->setObjectWatcher(($objectWatcher) ? $objectWatcher : $this->defaultObjectWatcher);
93
94
		$backend->setBackendCollection($backends);
95
96
		return $backend;
97
	}
98
}