1616use Wikibase \DataModel \SiteLink ;
1717use Wikibase \DataModel \SiteLinkList ;
1818use Wikibase \DataModel \Snak \Snak ;
19+ use Wikibase \DataModel \Statement \StatementList ;
1920use Wikibase \DataModel \Term \Fingerprint ;
2021
2122/**
@@ -37,7 +38,7 @@ class Item extends Entity {
3738 private $ siteLinks ;
3839
3940 /**
40- * @var Statement[]
41+ * @var StatementList
4142 */
4243 private $ statements ;
4344
@@ -47,9 +48,9 @@ class Item extends Entity {
4748 * @param ItemId|null $id
4849 * @param Fingerprint $fingerprint
4950 * @param SiteLinkList $links
50- * @param Statement[] $statements
51+ * @param StatementList $statements
5152 */
52- public function __construct ( ItemId $ id = null , Fingerprint $ fingerprint , SiteLinkList $ links , array $ statements ) {
53+ public function __construct ( ItemId $ id = null , Fingerprint $ fingerprint , SiteLinkList $ links , StatementList $ statements ) {
5354 $ this ->id = $ id ;
5455 $ this ->fingerprint = $ fingerprint ;
5556 $ this ->siteLinks = $ links ;
@@ -182,8 +183,8 @@ public static function newEmpty() {
182183 return new self (
183184 null ,
184185 Fingerprint::newEmpty (),
185- new SiteLinkList ( array () ),
186- array ()
186+ new SiteLinkList (),
187+ new StatementList ()
187188 );
188189 }
189190
@@ -199,9 +200,7 @@ public function getType() {
199200 }
200201
201202 /**
202- * @see Entity::newClaim
203- *
204- * @since 0.3
203+ * @deprecated since 1.0
205204 *
206205 * @param Snak $mainSnak
207206 *
@@ -222,7 +221,7 @@ public function newClaim( Snak $mainSnak ) {
222221 public function isEmpty () {
223222 return $ this ->fingerprint ->isEmpty ()
224223 && $ this ->siteLinks ->isEmpty ()
225- && empty ( $ this ->statements ) ;
224+ && $ this ->statements -> count () === 0 ;
226225 }
227226
228227 /**
@@ -237,27 +236,6 @@ public function clear() {
237236 $ this ->statements = array ();
238237 }
239238
240- private function getLinksInDiffFormat () {
241- $ links = array ();
242-
243- /**
244- * @var SiteLink $siteLink
245- */
246- foreach ( $ this ->siteLinks as $ siteLink ) {
247- $ links [$ siteLink ->getSiteId ()] = array (
248- 'name ' => $ siteLink ->getPageName (),
249- 'badges ' => array_map (
250- function ( ItemId $ id ) {
251- return $ id ->getSerialization ();
252- },
253- $ siteLink ->getBadges ()
254- )
255- );
256- }
257-
258- return $ links ;
259- }
260-
261239 /**
262240 * @see Entity::patchSpecificFields
263241 *
@@ -299,6 +277,27 @@ function( $idSerialization ) {
299277 }
300278 }
301279
280+ private function getLinksInDiffFormat () {
281+ $ links = array ();
282+
283+ /**
284+ * @var SiteLink $siteLink
285+ */
286+ foreach ( $ this ->siteLinks as $ siteLink ) {
287+ $ links [$ siteLink ->getSiteId ()] = array (
288+ 'name ' => $ siteLink ->getPageName (),
289+ 'badges ' => array_map (
290+ function ( ItemId $ id ) {
291+ return $ id ->getSerialization ();
292+ },
293+ $ siteLink ->getBadges ()
294+ )
295+ );
296+ }
297+
298+ return $ links ;
299+ }
300+
302301 private function patchClaims ( ItemDiff $ patch ) {
303302 $ patcher = new MapPatcher ();
304303
@@ -320,61 +319,63 @@ function( Claim $firstClaim, Claim $secondClaim ) {
320319 }
321320
322321 /**
323- * @see ClaimListAccess::addClaim
324- *
325- * @since 0.3
322+ * @deprecated since 1.0, use getStatements instead
326323 *
327- * @param Claim $claim
324+ * @param Claim $statement This needs to be a Statement as of 1.0
328325 *
329326 * @throws InvalidArgumentException
330327 */
331- public function addClaim ( Claim $ claim ) {
332- if ( $ claim ->getGuid () === null ) {
328+ public function addClaim ( Claim $ statement ) {
329+ if ( $ statement ->getGuid () === null ) {
333330 throw new InvalidArgumentException ( 'Can \'t add a Claim without a GUID. ' );
334331 }
335332
336- $ this ->statements [] = $ claim ;
333+ $ this ->statements -> addStatement ( $ statement ) ;
337334 }
338335
339336 /**
340337 * @since 1.0
341338 *
342- * @return Statement[]
339+ * @return StatementList
343340 */
344341 public function getStatements () {
345342 return $ this ->statements ;
346343 }
347344
345+ /**
346+ * @since 1.0
347+ *
348+ * @param StatementList $statements
349+ */
350+ public function setStatements ( StatementList $ statements ) {
351+ $ this ->statements = $ statements ;
352+ }
353+
348354 /**
349355 * @deprecated since 1.0, use getStatements instead
350356 *
351357 * @return Statement[]
352358 */
353359 public function getClaims () {
354- return $ this ->statements ;
360+ return $ this ->statements -> toArray () ;
355361 }
356362
357363 /**
358- * @since 0.4
364+ * @deprecated since 1.0, use setStatements instead
359365 *
360366 * @param Claims $claims
361367 */
362368 public function setClaims ( Claims $ claims ) {
363- $ this ->statements = iterator_to_array ( $ claims );
369+ $ this ->statements = new StatementList ( iterator_to_array ( $ claims ) );
364370 }
365371
366372 /**
367- * Convenience function to check if the entity contains any claims.
368- *
369- * On top of being a convenience function, this implementation allows for doing
370- * the check without forcing an unstub in contrast to count( $this->getClaims() ).
371- *
372- * @since 0.2
373+ * @deprecated since 1.0, use getStatements instead
373374 *
374375 * @return bool
375376 */
376377 public function hasClaims () {
377- return ! empty ( $ this ->statements ) ;
378+ return $ this ->statements -> count () !== 0 ;
378379 }
379380
380381 /**
@@ -405,12 +406,7 @@ public function equals( $that ) {
405406 */
406407 return $ this ->fingerprint ->equals ( $ that ->fingerprint )
407408 && $ this ->siteLinks ->equals ( $ that ->siteLinks )
408- && $ this ->statementsEqual ( $ that ->statements );
409- }
410-
411- private function statementsEqual ( array $ statements ) {
412- $ list = new Claims ( $ this ->statements );
413- return $ list ->equals ( new Claims ( $ statements ) );
409+ && $ that ->statements ->equals ( $ that ->statements );
414410 }
415411
416412}
0 commit comments