Passed
Push — refactor-referencelist ( 826e0b...168ca5 )
by Jeroen De
18:44 queued 15:47
created

Entity::getClaims()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0

1 Method

Rating   Name   Duplication   Size   Complexity  
Entity::clear() 0 1 ?
1
<?php
2
3
namespace Wikibase\DataModel\Entity;
4
5
use Comparable;
6
use Wikibase\DataModel\Statement\Statement;
7
use Wikibase\DataModel\Term\AliasGroup;
8
use Wikibase\DataModel\Term\AliasGroupList;
9
use Wikibase\DataModel\Term\FingerprintHolder;
10
use Wikibase\DataModel\Term\TermList;
11
12
/**
13
 * Represents a single Wikibase entity.
14
 * See https://www.mediawiki.org/wiki/Wikibase/DataModel#Values
15
 *
16
 * @deprecated since 1.0 - do not type hint against Entity. See
17
 * https://lists.wikimedia.org/pipermail/wikidata-tech/2014-June/000489.html
18
 *
19
 * @licence GNU GPL v2+
20
 * @author Jeroen De Dauw < [email protected] >
21
 */
22
abstract class Entity implements Comparable, FingerprintHolder, EntityDocument {
23
24
	/**
25
	 * Sets the value for the label in a certain value.
26
	 *
27
	 * @deprecated since 0.7.3 - use getFingerprint and setFingerprint
28
	 *
29
	 * @param string $languageCode
30
	 * @param string $value
31
	 */
32
	public function setLabel( $languageCode, $value ) {
33
		$this->getFingerprint()->setLabel( $languageCode, $value );
34
	}
35
36
	/**
37
	 * Sets the value for the description in a certain value.
38
	 *
39
	 * @deprecated since 0.7.3 - use getFingerprint and setFingerprint
40
	 *
41
	 * @param string $languageCode
42
	 * @param string $value
43
	 */
44
	public function setDescription( $languageCode, $value ) {
45
		$this->getFingerprint()->setDescription( $languageCode, $value );
46
	}
47
48
	/**
49
	 * Removes the labels in the specified languages.
50
	 *
51
	 * @deprecated since 0.7.3 - use getFingerprint and setFingerprint
52
	 *
53
	 * @param string $languageCode
54
	 */
55
	public function removeLabel( $languageCode ) {
56
		$this->getFingerprint()->removeLabel( $languageCode );
57
	}
58
59
	/**
60
	 * Removes the descriptions in the specified languages.
61
	 *
62
	 * @deprecated since 0.7.3 - use getFingerprint and setFingerprint
63
	 *
64
	 * @param string $languageCode
65
	 */
66
	public function removeDescription( $languageCode ) {
67
		$this->getFingerprint()->removeDescription( $languageCode );
68
	}
69
70
	/**
71
	 * Returns the aliases for the item in the language with the specified code.
72
	 *
73
	 * @deprecated since 0.7.3 - use getFingerprint and setFingerprint
74
	 *
75
	 * @param string $languageCode
76
	 *
77
	 * @return string[]
78
	 */
79
	public function getAliases( $languageCode ) {
80
		$aliases = $this->getFingerprint()->getAliasGroups();
81
82
		if ( $aliases->hasGroupForLanguage( $languageCode ) ) {
83
			return $aliases->getByLanguage( $languageCode )->getAliases();
84
		}
85
86
		return array();
87
	}
88
89
	/**
90
	 * Returns all the aliases for the item.
91
	 * The result is an array with language codes pointing to an array of aliases in the language they specify.
92
	 *
93
	 * @deprecated since 0.7.3 - use getFingerprint and setFingerprint
94
	 *
95
	 * @param string[]|null $languageCodes
96
	 *
97
	 * @return array[]
98
	 */
99
	public function getAllAliases( array $languageCodes = null ) {
100
		$aliases = $this->getFingerprint()->getAliasGroups();
101
102
		$textLists = array();
103
104
		/**
105
		 * @var AliasGroup $aliasGroup
106
		 */
107
		foreach ( $aliases as $languageCode => $aliasGroup ) {
108
			if ( $languageCodes === null || in_array( $languageCode, $languageCodes ) ) {
109
				$textLists[$languageCode] = $aliasGroup->getAliases();
110
			}
111
		}
112
113
		return $textLists;
114
	}
115
116
	/**
117
	 * Sets the aliases for the item in the language with the specified code.
118
	 *
119
	 * @deprecated since 0.7.3 - use getFingerprint and setFingerprint
120
	 *
121
	 * @param string $languageCode
122
	 * @param string[] $aliases
123
	 */
124
	public function setAliases( $languageCode, array $aliases ) {
125
		$this->getFingerprint()->setAliasGroup( $languageCode, $aliases );
126
	}
127
128
	/**
129
	 * Add the provided aliases to the aliases list of the item in the language with the specified code.
130
	 *
131
	 * @deprecated since 0.7.3 - use getFingerprint and setFingerprint
132
	 *
133
	 * @param string $languageCode
134
	 * @param string[] $aliases
135
	 */
136
	public function addAliases( $languageCode, array $aliases ) {
137
		$this->setAliases(
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::setAliases() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
138
			$languageCode,
139
			array_merge(
140
				$this->getAliases( $languageCode ),
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::getAliases() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
141
				$aliases
142
			)
143
		);
144
	}
145
146
	/**
147
	 * Removed the provided aliases from the aliases list of the item in the language with the specified code.
148
	 *
149
	 * @deprecated since 0.7.3 - use getFingerprint and setFingerprint
150
	 *
151
	 * @param string $languageCode
152
	 * @param string[] $aliases
153
	 */
154
	public function removeAliases( $languageCode, array $aliases ) {
155
		$this->setAliases(
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::setAliases() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
156
			$languageCode,
157
			array_diff(
158
				$this->getAliases( $languageCode ),
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::getAliases() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
159
				$aliases
160
			)
161
		);
162
	}
163
164
	/**
165
	 * Returns the descriptions of the entity in the provided languages.
166
	 *
167
	 * @deprecated since 0.7.3 - use getFingerprint and setFingerprint
168
	 *
169
	 * @param string[]|null $languageCodes Note that an empty array gives
170
	 * descriptions for no languages while a null pointer gives all
171
	 *
172
	 * @return string[] Found descriptions in given languages
173
	 */
174
	public function getDescriptions( array $languageCodes = null ) {
175
		return $this->getMultilangTexts( 'description', $languageCodes );
176
	}
177
178
	/**
179
	 * Returns the labels of the entity in the provided languages.
180
	 *
181
	 * @deprecated since 0.7.3 - use getFingerprint and setFingerprint
182
	 *
183
	 * @param string[]|null $languageCodes Note that an empty array gives
184
	 * labels for no languages while a null pointer gives all
185
	 *
186
	 * @return string[] Found labels in given languages
187
	 */
188
	public function getLabels( array $languageCodes = null ) {
189
		return $this->getMultilangTexts( 'label', $languageCodes );
190
	}
191
192
	/**
193
	 * Returns the description of the entity in the language with the provided code,
194
	 * or false in cases there is none in this language.
195
	 *
196
	 * @deprecated since 0.7.3 - use getFingerprint and setFingerprint
197
	 *
198
	 * @param string $languageCode
199
	 *
200
	 * @return string|bool
201
	 */
202
	public function getDescription( $languageCode ) {
203
		if ( !$this->getFingerprint()->hasDescription( $languageCode ) ) {
204
			return false;
205
		}
206
207
		return $this->getFingerprint()->getDescription( $languageCode )->getText();
208
	}
209
210
	/**
211
	 * Returns the label of the entity in the language with the provided code,
212
	 * or false in cases there is none in this language.
213
	 *
214
	 * @deprecated since 0.7.3 - use getFingerprint and setFingerprint
215
	 *
216
	 * @param string $languageCode
217
	 *
218
	 * @return string|bool
219
	 */
220
	public function getLabel( $languageCode ) {
221
		if ( !$this->getFingerprint()->hasLabel( $languageCode ) ) {
222
			return false;
223
		}
224
225
		return $this->getFingerprint()->getLabel( $languageCode )->getText();
226
	}
227
228
	/**
229
	 * Get texts from an item with a field specifier.
230
	 *
231
	 * @param string $fieldKey
232
	 * @param string[]|null $languageCodes
233
	 *
234
	 * @return string[]
235
	 */
236
	private function getMultilangTexts( $fieldKey, array $languageCodes = null ) {
237
		if ( $fieldKey === 'label' ) {
238
			$textList = $this->getFingerprint()->getLabels()->toTextArray();
239
		} else {
240
			$textList = $this->getFingerprint()->getDescriptions()->toTextArray();
241
		}
242
243
		if ( $languageCodes !== null ) {
244
			$textList = array_intersect_key( $textList, array_flip( $languageCodes ) );
245
		}
246
247
		return $textList;
248
	}
249
250
	/**
251
	 * Replaces the currently set labels with the provided ones.
252
	 * The labels are provided as an associative array where the keys are
253
	 * language codes pointing to the label in that language.
254
	 *
255
	 * @since 0.4
256
	 * @deprecated since 0.7.3 - use getFingerprint and setFingerprint
257
	 *
258
	 * @param string[] $labels
259
	 */
260
	public function setLabels( array $labels ) {
261
		$this->getFingerprint()->setLabels( new TermList() );
262
263
		foreach ( $labels as $languageCode => $labelText ) {
264
			$this->setLabel( $languageCode, $labelText );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::setLabel() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
265
		}
266
	}
267
268
	/**
269
	 * Replaces the currently set descriptions with the provided ones.
270
	 * The descriptions are provided as an associative array where the keys are
271
	 * language codes pointing to the description in that language.
272
	 *
273
	 * @since 0.4
274
	 * @deprecated since 0.7.3 - use getFingerprint and setFingerprint
275
	 *
276
	 * @param string[] $descriptions
277
	 */
278
	public function setDescriptions( array $descriptions ) {
279
		$this->getFingerprint()->setDescriptions( new TermList() );
280
281
		foreach ( $descriptions as $languageCode => $descriptionText ) {
282
			$this->setDescription( $languageCode, $descriptionText );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::setDescription() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
283
		}
284
	}
285
286
	/**
287
	 * Replaces the currently set aliases with the provided ones.
288
	 * The aliases are provided as an associative array where the keys are
289
	 * language codes pointing to an array value that holds the aliases
290
	 * in that language.
291
	 *
292
	 * @since 0.4
293
	 * @deprecated since 0.7.3 - use getFingerprint and setFingerprint
294
	 *
295
	 * @param array[] $aliasLists
296
	 */
297
	public function setAllAliases( array $aliasLists ) {
298
		$this->getFingerprint()->setAliasGroups( new AliasGroupList() );
299
300
		foreach ( $aliasLists as $languageCode => $aliasList ) {
301
			$this->setAliases( $languageCode, $aliasList );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::setAliases() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
302
		}
303
	}
304
305
	/**
306
	 * Returns a deep copy of the entity.
307
	 *
308
	 * @since 0.1
309
	 *
310
	 * @return self
311
	 */
312
	public function copy() {
313
		return unserialize( serialize( $this ) );
314
	}
315
316
	/**
317
	 * Removes all content from the Entity.
318
	 * The id is not part of the content.
319
	 *
320
	 * @since 0.1
321
	 * @deprecated since 1.0
322
	 */
323
	public abstract function clear();
324
325
}
326