From 0c1d280dc5d3b8ce2631469a6ff5a1c86e1d2294 Mon Sep 17 00:00:00 2001 From: Bene Date: Sat, 20 Sep 2014 10:27:20 +0200 Subject: [PATCH 1/2] Use ByPropertyIdGrouper in Claims and deprecate ByPropertyIdArray --- RELEASE-NOTES.md | 4 ++++ src/ByPropertyIdArray.php | 1 + src/Claim/Claims.php | 10 +++++----- tests/unit/Claim/ClaimsTest.php | 19 +++++-------------- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 54c28dee..469a71db 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -13,6 +13,10 @@ * Added `ByPropertyIdGrouper` * Added `BestStatementsFinder` +#### Deprecations + +* Deprecated `ByPropertyIdArray` in favour of `ByPropertyIdGrouper` + ## Version 1.0 (2014-09-02) #### Breaking changes diff --git a/src/ByPropertyIdArray.php b/src/ByPropertyIdArray.php index 37a7d64c..8110b70a 100644 --- a/src/ByPropertyIdArray.php +++ b/src/ByPropertyIdArray.php @@ -36,6 +36,7 @@ * o3 (p2) ---> move to index 0 -/ o1 (p1) * * @since 0.2 + * @deprecated since 1.1 - use ByPropertyIdGrouper instead * * @licence GNU GPL v2+ * @author H. Snater < mediawiki@snater.com > diff --git a/src/Claim/Claims.php b/src/Claim/Claims.php index ba2f6d84..415517b8 100644 --- a/src/Claim/Claims.php +++ b/src/Claim/Claims.php @@ -2,12 +2,13 @@ namespace Wikibase\DataModel\Claim; +use ArrayAccess; use ArrayObject; use Comparable; use Hashable; use InvalidArgumentException; use Traversable; -use Wikibase\DataModel\ByPropertyIdArray; +use Wikibase\DataModel\ByPropertyIdGrouper; use Wikibase\DataModel\Entity\PropertyId; use Wikibase\DataModel\Snak\Snak; @@ -317,14 +318,13 @@ public function getGuids() { * @return Claims */ public function getClaimsForProperty( PropertyId $propertyId ) { - $claimsByProp = new ByPropertyIdArray( $this ); - $claimsByProp->buildIndex(); + $byPropertyIdGrouper = new ByPropertyIdGrouper( $this ); - if ( !( in_array( $propertyId, $claimsByProp->getPropertyIds() ) ) ) { + if ( !$byPropertyIdGrouper->hasPropertyId( $propertyId ) ) { return new self(); } - return new self( $claimsByProp->getByPropertyId( $propertyId ) ); + return new self( $byPropertyIdGrouper->getByPropertyId( $propertyId ) ); } /** diff --git a/tests/unit/Claim/ClaimsTest.php b/tests/unit/Claim/ClaimsTest.php index cef8124c..26e281a0 100644 --- a/tests/unit/Claim/ClaimsTest.php +++ b/tests/unit/Claim/ClaimsTest.php @@ -2,25 +2,16 @@ namespace Wikibase\Test; -use DataValues\StringValue; -use Diff\DiffOp\Diff\Diff; -use Diff\DiffOp\DiffOpAdd; -use Diff\DiffOp\DiffOpChange; -use Diff\DiffOp\DiffOpRemove; use InvalidArgumentException; use ReflectionClass; -use Wikibase\DataModel\ByPropertyIdArray; use Wikibase\DataModel\Claim\Claim; +use Wikibase\DataModel\Claim\ClaimList; use Wikibase\DataModel\Claim\Claims; -use Wikibase\DataModel\Statement\Statement; use Wikibase\DataModel\Entity\PropertyId; -use Wikibase\DataModel\Reference; -use Wikibase\DataModel\ReferenceList; use Wikibase\DataModel\Snak\PropertyNoValueSnak; use Wikibase\DataModel\Snak\PropertySomeValueSnak; -use Wikibase\DataModel\Snak\PropertyValueSnak; use Wikibase\DataModel\Snak\Snak; -use Wikibase\DataModel\Snak\SnakList; +use Wikibase\DataModel\Statement\Statement; /** * @covers Wikibase\DataModel\Claim\Claims @@ -66,10 +57,10 @@ public function testArrayObjectNotConstructedFromObject() { $claim1 = $this->makeClaim( new PropertyNoValueSnak( 1 ) ); $claim2 = $this->makeClaim( new PropertyNoValueSnak( 2 ) ); - $byPropertyIdArray = new ByPropertyIdArray(); - $byPropertyIdArray->append( $claim1 ); + $claimList = new ClaimList(); + $claimList->addClaim( $claim1 ); - $claims = new Claims( $byPropertyIdArray ); + $claims = new Claims( $claimList ); // According to the documentation append() "cannot be called when the ArrayObject was // constructed from an object." This test makes sure it was not constructed from an object. $claims->append( $claim2 ); From 6d866f7a4e666d694eab633b10b30e756853f8fa Mon Sep 17 00:00:00 2001 From: Bene Date: Fri, 26 Sep 2014 23:13:30 +0200 Subject: [PATCH 2/2] Remove deprecation per discussion --- RELEASE-NOTES.md | 4 ---- src/ByPropertyIdArray.php | 1 - 2 files changed, 5 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 469a71db..54c28dee 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -13,10 +13,6 @@ * Added `ByPropertyIdGrouper` * Added `BestStatementsFinder` -#### Deprecations - -* Deprecated `ByPropertyIdArray` in favour of `ByPropertyIdGrouper` - ## Version 1.0 (2014-09-02) #### Breaking changes diff --git a/src/ByPropertyIdArray.php b/src/ByPropertyIdArray.php index 8110b70a..37a7d64c 100644 --- a/src/ByPropertyIdArray.php +++ b/src/ByPropertyIdArray.php @@ -36,7 +36,6 @@ * o3 (p2) ---> move to index 0 -/ o1 (p1) * * @since 0.2 - * @deprecated since 1.1 - use ByPropertyIdGrouper instead * * @licence GNU GPL v2+ * @author H. Snater < mediawiki@snater.com >