Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Claim/Claims.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 ) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is less readable than before

}

/**
Expand Down
19 changes: 5 additions & 14 deletions tests/unit/Claim/ClaimsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 );
Expand Down