WikibaseFactory   A
last analyzed

Complexity

Total Complexity 28

Size/Duplication

Total Lines 267
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 28

Test Coverage

Coverage 81.11%

Importance

Changes 0
Metric Value
wmc 28
lcom 1
cbo 28
dl 0
loc 267
rs 10
c 0
b 0
f 0
ccs 73
cts 90
cp 0.8111

28 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A newRevisionSaver() 0 7 1
A newRevisionGetter() 0 6 1
A newRevisionsGetter() 0 6 1
A newValueParser() 0 6 1
A newValueFormatter() 0 6 1
A newItemMerger() 0 3 1
A newAliasGroupSetter() 0 3 1
A newDescriptionSetter() 0 3 1
A newLabelSetter() 0 3 1
A newReferenceRemover() 0 3 1
A newReferenceSetter() 0 6 1
A newSiteLinkLinker() 0 3 1
A newSiteLinkSetter() 0 3 1
A newBadgeIdsGetter() 0 3 1
A newRedirectCreator() 0 3 1
A newDataModelDeserializerFactory() 0 6 1
A newDataModelSerializerFactory() 0 3 1
A newStatementGetter() 0 6 1
A newStatementSetter() 0 6 1
A newStatementCreator() 0 6 1
A newStatementRemover() 0 3 1
A newWikibaseApi() 0 3 1
A newEntityLookup() 0 3 1
A newItemLookup() 0 3 1
A newPropertyLookup() 0 3 1
A newTermLookup() 0 3 1
A newEntityDocumentSaver() 0 3 1
1
<?php
2
3
namespace Wikibase\Api;
4
5
use Deserializers\Deserializer;
6
use Mediawiki\Api\MediawikiApi;
7
use Serializers\Serializer;
8
use Wikibase\Api\Lookup\EntityApiLookup;
9
use Wikibase\Api\Lookup\ItemApiLookup;
10
use Wikibase\Api\Lookup\PropertyApiLookup;
11
use Wikibase\Api\Service\AliasGroupSetter;
12
use Wikibase\Api\Service\BadgeIdsGetter;
13
use Wikibase\Api\Service\DescriptionSetter;
14
use Wikibase\Api\Service\EntityDocumentSaver;
15
use Wikibase\Api\Service\ItemMerger;
16
use Wikibase\Api\Service\LabelSetter;
17
use Wikibase\Api\Service\RedirectCreator;
18
use Wikibase\Api\Service\ReferenceRemover;
19
use Wikibase\Api\Service\ReferenceSetter;
20
use Wikibase\Api\Service\RevisionGetter;
21
use Wikibase\Api\Service\RevisionSaver;
22
use Wikibase\Api\Service\RevisionsGetter;
23
use Wikibase\Api\Service\SiteLinkLinker;
24
use Wikibase\Api\Service\SiteLinkSetter;
25
use Wikibase\Api\Service\StatementCreator;
26
use Wikibase\Api\Service\StatementGetter;
27
use Wikibase\Api\Service\StatementRemover;
28
use Wikibase\Api\Service\StatementSetter;
29
use Wikibase\Api\Service\ValueFormatter;
30
use Wikibase\Api\Service\ValueParser;
31
use Wikibase\DataModel\DeserializerFactory;
32
use Wikibase\DataModel\Entity\BasicEntityIdParser;
33
use Wikibase\DataModel\SerializerFactory;
34
use Wikibase\DataModel\Services\Lookup\EntityLookup;
35
use Wikibase\DataModel\Services\Lookup\EntityRetrievingTermLookup;
36
use Wikibase\DataModel\Services\Lookup\ItemLookup;
37
use Wikibase\DataModel\Services\Lookup\PropertyLookup;
38
use Wikibase\DataModel\Services\Lookup\TermLookup;
39
40
/**
41
 * @author Addshore
42
 *
43
 * @access public
44
 */
45
class WikibaseFactory {
46
47
	/**
48
	 * @var MediawikiApi
49
	 */
50
	private $api;
51
52
	/**
53
	 * @var Deserializer
54
	 */
55
	private $dataValueDeserializer;
56
57
	/**
58
	 * @var Serializer
59
	 */
60
	private $dataValueSerializer;
61
62
	/**
63
	 * @param MediawikiApi $api
64
	 * @param Deserializer $dvDeserializer
65
	 * @param Serializer $dvSerializer
66
	 */
67 16
	public function __construct( MediawikiApi $api, Deserializer $dvDeserializer, Serializer $dvSerializer ) {
68 16
		$this->api = $api;
69 16
		$this->dataValueDeserializer = $dvDeserializer;
70 16
		$this->dataValueSerializer = $dvSerializer;
71 16
	}
72
73
	/**
74
	 * @since 0.1
75
	 * @return RevisionSaver
76
	 */
77 1
	public function newRevisionSaver() {
78 1
		return new RevisionSaver(
79 1
			$this->newWikibaseApi(),
80 1
			$this->newDataModelDeserializerFactory()->newEntityDeserializer(),
81 1
			$this->newDataModelSerializerFactory()->newEntitySerializer()
82 1
		);
83
	}
84
85
	/**
86
	 * @since 0.1
87
	 * @return RevisionGetter
88
	 */
89 1
	public function newRevisionGetter() {
90 1
		return new RevisionGetter(
91 1
			$this->api,
92 1
			$this->newDataModelDeserializerFactory()->newEntityDeserializer()
93 1
		);
94
	}
95
96
	/**
97
	 * @since 0.4
98
	 * @return RevisionsGetter
99
	 */
100 1
	public function newRevisionsGetter() {
101
		return new RevisionsGetter(
102 1
			$this->api,
103
			$this->newDataModelDeserializerFactory()->newEntityDeserializer()
104
		);
105
	}
106
107
	/**
108
	 * @since 0.2
109
	 * @return ValueParser
110
	 */
111 1
	public function newValueParser() {
112 1
		return new ValueParser(
113 1
			$this->api,
114 1
			$this->dataValueDeserializer
115 1
		);
116
	}
117
118
	/**
119
	 * @since 0.2
120
	 * @return ValueFormatter
121
	 */
122 1
	public function newValueFormatter() {
123 1
		return new ValueFormatter(
124 1
			$this->api,
125 1
			$this->dataValueSerializer
126 1
		);
127
	}
128
129
	/**
130
	 * @since 0.2
131
	 * @return ItemMerger
132
	 */
133 1
	public function newItemMerger() {
134 1
		return new ItemMerger( $this->newWikibaseApi() );
135
	}
136
137
	/**
138
	 * @since 0.2
139
	 * @return AliasGroupSetter
140
	 */
141 1
	public function newAliasGroupSetter() {
142 1
		return new AliasGroupSetter( $this->newWikibaseApi() );
143
	}
144
145
	/**
146
	 * @since 0.2
147
	 * @return DescriptionSetter
148
	 */
149 1
	public function newDescriptionSetter() {
150 1
		return new DescriptionSetter( $this->newWikibaseApi() );
151
	}
152
153
	/**
154
	 * @since 0.2
155
	 * @return LabelSetter
156
	 */
157 1
	public function newLabelSetter() {
158 1
		return new LabelSetter( $this->newWikibaseApi() );
159
	}
160
161
	/**
162
	 * @since 0.2
163
	 * @return ReferenceRemover
164
	 */
165 1
	public function newReferenceRemover() {
166 1
		return new ReferenceRemover( $this->newWikibaseApi() );
167
	}
168
169
	/**
170
	 * @since 0.2
171
	 * @return ReferenceSetter
172
	 */
173 1
	public function newReferenceSetter() {
174 1
		return new ReferenceSetter(
175 1
			$this->newWikibaseApi(),
176 1
			$this->newDataModelSerializerFactory()->newReferenceSerializer()
177 1
		);
178
	}
179
180
	/**
181
	 * @since 0.2
182
	 * @return SiteLinkLinker
183
	 */
184 1
	public function newSiteLinkLinker() {
185 1
		return new SiteLinkLinker( $this->newWikibaseApi() );
186
	}
187
188
	/**
189
	 * @since 0.2
190
	 * @return SiteLinkSetter
191
	 */
192 1
	public function newSiteLinkSetter() {
193 1
		return new SiteLinkSetter( $this->newWikibaseApi() );
194
	}
195
196
	/**
197
	 * @since 0.5
198
	 * @return BadgeIdsGetter
199
	 */
200
	public function newBadgeIdsGetter() {
201
		return new BadgeIdsGetter( $this->api );
202
	}
203
204
	/**
205
	 * @since 0.5
206
	 * @return RedirectCreator
207
	 */
208
	public function newRedirectCreator() {
209
		return new RedirectCreator( $this->newWikibaseApi() );
210
	}
211
212 3
	private function newDataModelDeserializerFactory() {
213 3
		return new DeserializerFactory(
214 3
			$this->dataValueDeserializer,
215 3
			new BasicEntityIdParser()
216 3
		);
217
	}
218
219 3
	private function newDataModelSerializerFactory() {
220 3
		return new SerializerFactory( $this->dataValueSerializer );
221
	}
222
223
	/**
224
	 * @since 0.5
225
	 * @return StatementGetter
226
	 */
227 1
	public function newStatementGetter() {
228 1
		return new StatementGetter(
229 1
			$this->api,
230 1
			$this->newDataModelDeserializerFactory()->newStatementDeserializer()
231 1
		);
232
	}
233
234
	/**
235
	 * @since 0.5
236
	 * @return StatementSetter
237
	 */
238 1
	public function newStatementSetter() {
239 1
		return new StatementSetter(
240 1
			$this->newWikibaseApi(),
241 1
			$this->newDataModelSerializerFactory()->newStatementSerializer()
242 1
		);
243
	}
244
245
	/**
246
	 * @since 0.5
247
	 * @return StatementCreator
248
	 */
249 1
	public function newStatementCreator() {
250 1
		return new StatementCreator(
251 1
			$this->newWikibaseApi(),
252 1
			$this->dataValueSerializer
253 1
		);
254
	}
255
256
	/**
257
	 * @since 0.5
258
	 * @return StatementRemover
259
	 */
260 1
	public function newStatementRemover() {
261 1
		return new StatementRemover( $this->newWikibaseApi() );
262
	}
263
264
	/**
265
	 * @return WikibaseApi
266
	 */
267 12
	private function newWikibaseApi() {
268 12
		return new WikibaseApi( $this->api );
269
	}
270
271
	/**
272
	 * @since 0.7
273
	 * @return EntityLookup
274
	 */
275
	public function newEntityLookup() {
276
		return new EntityApiLookup( $this->newRevisionGetter() );
277
	}
278
279
	/**
280
	 * @since 0.7
281
	 * @return ItemLookup
282
	 */
283
	public function newItemLookup() {
284
		return new ItemApiLookup( $this->newEntityLookup() );
285
	}
286
287
	/**
288
	 * @since 0.7
289
	 * @return PropertyLookup
290
	 */
291
	public function newPropertyLookup() {
292
		return new PropertyApiLookup( $this->newEntityLookup() );
293
	}
294
295
	/**
296
	 * @since 0.7
297
	 * @return TermLookup
298
	 */
299
	public function newTermLookup() {
300
		return new EntityRetrievingTermLookup( $this->newEntityLookup() );
301
	}
302
303
	/**
304
	 * @since 0.7
305
	 * @return EntityDocumentSaver
306
	 */
307
	public function newEntityDocumentSaver() {
308
		return new EntityDocumentSaver( $this->newRevisionSaver() );
309
	}
310
311
}
312