Skip to content

Commit c21c4d8

Browse files
committed
Merge pull request #411 from wmde/getBestClaims
Remove methods from the deprecated Claims class that are no depended on by users
2 parents aab569b + 123bd51 commit c21c4d8

3 files changed

Lines changed: 8 additions & 430 deletions

File tree

RELEASE-NOTES.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
* `Statement::setClaim` and `Statement::getClaim` have been removed
1010
* Removed `ClaimList`
1111
* Removed `ClaimListAccess`
12+
* Removed `Claims::getBestClaims` (you can use `StatementList::getBestStatements` instead)
13+
* Removed `Claims::getByRank` and `Claims::getByRanks` (you can use `StatementList::getWithRank` instead)
14+
* Removed `Claims::getMainSnaks` (you can use `StatementList::getMainSnaks` instead)
15+
* Removed `Claims::getClaimsForProperty` (you can use `StatementList::getWithPropertyId` instead)
16+
* Removed `Claims::getHashes`
17+
* Removed `Claims::getGuids`
18+
* Removed `Claims::equals` (and `Claims` no longer implements `Comparable`)
1219

1320
## Version 2.6.0 (2015-03-08)
1421

src/Claim/Claims.php

Lines changed: 1 addition & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* @author Daniel Kinzler
2323
* @author H. Snater < mediawiki@snater.com >
2424
*/
25-
class Claims extends ArrayObject implements Hashable, Comparable {
25+
class Claims extends ArrayObject implements Hashable {
2626

2727
/**
2828
* @see GenericArrayObject::__construct
@@ -279,76 +279,6 @@ public function offsetUnset( $guid ) {
279279
parent::offsetUnset( $key );
280280
}
281281

282-
/**
283-
* Get array of Claim guids
284-
*
285-
* @since 0.4
286-
*
287-
* @return string[]
288-
*/
289-
public function getGuids() {
290-
return array_map( function ( Claim $claim ) {
291-
return $claim->getGuid();
292-
}, iterator_to_array( $this ) );
293-
}
294-
295-
/**
296-
* Returns the claims for the given property.
297-
*
298-
* @since 0.4
299-
*
300-
* @param PropertyId $propertyId
301-
*
302-
* @return Claims
303-
*/
304-
public function getClaimsForProperty( PropertyId $propertyId ) {
305-
$byPropertyIdGrouper = new ByPropertyIdGrouper( $this );
306-
307-
if ( !$byPropertyIdGrouper->hasPropertyId( $propertyId ) ) {
308-
return new self();
309-
}
310-
311-
return new self( $byPropertyIdGrouper->getByPropertyId( $propertyId ) );
312-
}
313-
314-
/**
315-
* Returns the main Snaks of the claims in this list.
316-
*
317-
* @since 0.4
318-
*
319-
* @return Snak[]
320-
*/
321-
public function getMainSnaks() {
322-
$snaks = array();
323-
324-
/* @var Claim $claim */
325-
foreach ( $this as $claim ) {
326-
$guid = $claim->getGuid();
327-
$snaks[$guid] = $claim->getMainSnak();
328-
}
329-
330-
return $snaks;
331-
}
332-
333-
/**
334-
* Returns a map from GUIDs to claim hashes.
335-
*
336-
* @since 0.4
337-
*
338-
* @return string[]
339-
*/
340-
public function getHashes() {
341-
$snaks = array();
342-
343-
/* @var Claim $claim */
344-
foreach ( $this as $claim ) {
345-
$guid = $claim->getGuid();
346-
$snaks[$guid] = $claim->getHash();
347-
}
348-
349-
return $snaks;
350-
}
351-
352282
/**
353283
* Returns a hash based on the value of the object.
354284
* The hash is based on the hashes of the claims contained,
@@ -376,107 +306,4 @@ public function isEmpty() {
376306
return !$this->getIterator()->valid();
377307
}
378308

379-
/**
380-
* Returns a new instance only containing the claims with the given rank.
381-
*
382-
* @since 0.7
383-
*
384-
* @param int $rank
385-
*
386-
* @return Claims
387-
*/
388-
public function getByRank( $rank ) {
389-
$claims = new self();
390-
391-
/* @var Claim $claim */
392-
foreach ( $this as $claim ) {
393-
if ( $claim->getRank() === $rank ) {
394-
$claims[] = $claim;
395-
}
396-
}
397-
398-
return $claims;
399-
}
400-
401-
/**
402-
* Returns a new instance only containing the claims with the given ranks.
403-
*
404-
* @since 0.7.2
405-
*
406-
* @param int[] $ranks
407-
*
408-
* @return Claims
409-
*/
410-
public function getByRanks( array $ranks ) {
411-
$ranks = array_flip( $ranks );
412-
$claims = new self();
413-
414-
/* @var Claim $claim */
415-
foreach ( $this as $claim ) {
416-
if ( isset( $ranks[$claim->getRank()] ) ) {
417-
$claims[] = $claim;
418-
}
419-
}
420-
421-
return $claims;
422-
}
423-
424-
/**
425-
* Returns a new instance only containing the best claims (these are the highest
426-
* ranked claims, but never deprecated ones). This implementation ignores the properties
427-
* so you probably want to call Claims::getClaimsForProperty first or use
428-
* StatementList::getBestStatementPerProperty instead.
429-
*
430-
* @see Claims::getClaimsForProperty
431-
* @see StatementList::getBestStatementPerProperty
432-
*
433-
* @since 0.7
434-
*
435-
* @return Claims
436-
*/
437-
public function getBestClaims() {
438-
$rank = Statement::RANK_PREFERRED;
439-
440-
do {
441-
$claims = $this->getByRank( $rank );
442-
$rank--;
443-
} while ( $claims->isEmpty() && $rank > Statement::RANK_DEPRECATED );
444-
445-
return $claims;
446-
}
447-
448-
/**
449-
* @see Comparable::equals
450-
*
451-
* @since 0.7.4
452-
*
453-
* @param mixed $target
454-
*
455-
* @return bool
456-
*/
457-
public function equals( $target ) {
458-
if ( $this === $target ) {
459-
return true;
460-
}
461-
462-
if ( !( $target instanceof self )
463-
|| $this->count() !== $target->count()
464-
) {
465-
return false;
466-
}
467-
468-
foreach ( $this as $claim ) {
469-
if ( !$target->hasExactClaim( $claim ) ) {
470-
return false;
471-
}
472-
}
473-
474-
return true;
475-
}
476-
477-
private function hasExactClaim( Claim $claim ) {
478-
return $this->hasClaim( $claim )
479-
&& $this->getClaimWithGuid( $claim->getGuid() )->equals( $claim );
480-
}
481-
482309
}

0 commit comments

Comments
 (0)