Passed
Pull Request — master (#605)
by Jeroen De
14:57 queued 12:00
created

Entity::getLabels()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 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 6
	public function removeLabel( $languageCode ) {
56 6
		$this->getFingerprint()->removeLabel( $languageCode );
57 6
	}
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 6
	public function removeDescription( $languageCode ) {
67 6
		$this->getFingerprint()->removeDescription( $languageCode );
68 6
	}
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 60
	public function getAliases( $languageCode ) {
80 60
		$aliases = $this->getFingerprint()->getAliasGroups();
81
82 60
		if ( $aliases->hasGroupForLanguage( $languageCode ) ) {
83 48
			return $aliases->getByLanguage( $languageCode )->getAliases();
84
		}
85
86 32
		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 4
	public function getAllAliases( array $languageCodes = null ) {
100 4
		$aliases = $this->getFingerprint()->getAliasGroups();
101
102 4
		$textLists = array();
103
104
		/**
105
		 * @var AliasGroup $aliasGroup
106
		 */
107 4
		foreach ( $aliases as $languageCode => $aliasGroup ) {
108
			if ( $languageCodes === null || in_array( $languageCode, $languageCodes ) ) {
109
				$textLists[$languageCode] = $aliasGroup->getAliases();
110
			}
111 4
		}
112
113 4
		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 24
	public function addAliases( $languageCode, array $aliases ) {
137 24
		$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 24
			$languageCode,
139 24
			array_merge(
140 24
				$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 24
			)
143 24
		);
144 24
	}
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 10
	public function removeAliases( $languageCode, array $aliases ) {
155 10
		$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 10
			$languageCode,
157 10
			array_diff(
158 10
				$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 10
			)
161 10
		);
162 10
	}
163
164
	/**
165
	 * Returns the description of the entity in the language with the provided code,
166
	 * or false in cases there is none in this language.
167
	 *
168
	 * @deprecated since 0.7.3 - use getFingerprint and setFingerprint
169
	 *
170
	 * @param string $languageCode
171
	 *
172
	 * @return string|bool
173
	 */
174 4
	public function getDescription( $languageCode ) {
175 4
		if ( !$this->getFingerprint()->hasDescription( $languageCode ) ) {
176
			return false;
177
		}
178
179
		return $this->getFingerprint()->getDescription( $languageCode )->getText();
180
	}
181
182
	/**
183
	 * Returns the label of the entity in the language with the provided code,
184
	 * or false in cases there is none in this language.
185
	 *
186
	 * @deprecated since 0.7.3 - use getFingerprint and setFingerprint
187
	 *
188 4
	 * @param string $languageCode
189 4
	 *
190
	 * @return string|bool
191
	 */
192
	public function getLabel( $languageCode ) {
193
		if ( !$this->getFingerprint()->hasLabel( $languageCode ) ) {
194
			return false;
195
		}
196
197
		return $this->getFingerprint()->getLabel( $languageCode )->getText();
198
	}
199
200
	/**
201
	 * Replaces the currently set aliases with the provided ones.
202 18
	 * The aliases are provided as an associative array where the keys are
203 18
	 * language codes pointing to an array value that holds the aliases
204 12
	 * in that language.
205
	 *
206
	 * @since 0.4
207 12
	 * @deprecated since 0.7.3 - use getFingerprint and setFingerprint
208
	 *
209
	 * @param array[] $aliasLists
210
	 */
211
	public function setAllAliases( array $aliasLists ) {
212
		$this->getFingerprint()->setAliasGroups( new AliasGroupList() );
213
214
		foreach ( $aliasLists as $languageCode => $aliasList ) {
215
			$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...
216
		}
217
	}
218
219
	/**
220 18
	 * Returns a deep copy of the entity.
221 18
	 *
222 12
	 * @since 0.1
223
	 *
224
	 * @return self
225 12
	 */
226
	public function copy() {
227
		return unserialize( serialize( $this ) );
228
	}
229
230
	/**
231
	 * Removes all content from the Entity.
232
	 * The id is not part of the content.
233
	 *
234
	 * @since 0.1
235
	 * @deprecated since 1.0
236 4
	 */
237 4
	public abstract function clear();
238 4
239
}
240