Skip to content

Commit 016f4c0

Browse files
committed
Merge pull request #615 from wmde/entitydocument-equals
Add equals to EntityDocument
2 parents ef2f716 + 74bce34 commit 016f4c0

5 files changed

Lines changed: 31 additions & 29 deletions

File tree

RELEASE-NOTES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* Removed `ReferenceList::removeDuplicates`
1010
* `ReferenceList` no longer derives from `SplObjectStorage`, though still implements `Countable`
1111
* Removed `HashableObjectStorage`
12+
* Added `EntityDocument::equals`
13+
* `Entity` no longer implements `Comparable`
1214

1315
#### Other changes
1416

src/Entity/Entity.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Wikibase\DataModel\Entity;
44

5-
use Comparable;
6-
use Wikibase\DataModel\Statement\Statement;
75
use Wikibase\DataModel\Term\AliasGroup;
86
use Wikibase\DataModel\Term\AliasGroupList;
97
use Wikibase\DataModel\Term\FingerprintHolder;
@@ -19,7 +17,7 @@
1917
* @licence GNU GPL v2+
2018
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
2119
*/
22-
abstract class Entity implements Comparable, FingerprintHolder, EntityDocument {
20+
abstract class Entity implements FingerprintHolder, EntityDocument {
2321

2422
/**
2523
* Sets the value for the label in a certain value.

src/Entity/EntityDocument.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,16 @@ public function setId( $id );
5252
*/
5353
public function isEmpty();
5454

55+
/**
56+
* Two entities are considered equal if they are of the same
57+
* type and have the same value. The value does not include
58+
* the id, so entities with the same value but different id
59+
* are considered equal.
60+
*
61+
* @param EntityDocument $entity
62+
*
63+
* @return bool
64+
*/
65+
public function equals( EntityDocument $entity );
66+
5567
}

src/Entity/Item.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -300,28 +300,23 @@ public function setStatements( StatementList $statements ) {
300300
}
301301

302302
/**
303-
* @see Comparable::equals
304-
*
305-
* Two items are considered equal if they are of the same
306-
* type and have the same value. The value does not include
307-
* the id, so entities with the same value but different id
308-
* are considered equal.
303+
* @see EntityDocument::equals
309304
*
310305
* @since 0.1
311306
*
312-
* @param mixed $target
307+
* @param EntityDocument $entity
313308
*
314309
* @return bool
315310
*/
316-
public function equals( $target ) {
317-
if ( $this === $target ) {
311+
public function equals( EntityDocument $entity ) {
312+
if ( $this === $entity ) {
318313
return true;
319314
}
320315

321-
return $target instanceof self
322-
&& $this->fingerprint->equals( $target->fingerprint )
323-
&& $this->siteLinks->equals( $target->siteLinks )
324-
&& $this->statements->equals( $target->statements );
316+
return $entity instanceof self
317+
&& $this->fingerprint->equals( $entity->fingerprint )
318+
&& $this->siteLinks->equals( $entity->siteLinks )
319+
&& $this->statements->equals( $entity->statements );
325320
}
326321

327322
}

src/Entity/Property.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -190,28 +190,23 @@ public static function newFromType( $dataTypeId ) {
190190
}
191191

192192
/**
193-
* @see Comparable::equals
194-
*
195-
* Two properties are considered equal if they are of the same
196-
* type and have the same value. The value does not include
197-
* the id, so entities with the same value but different id
198-
* are considered equal.
193+
* @see EntityDocument::equals
199194
*
200195
* @since 0.1
201196
*
202-
* @param mixed $target
197+
* @param EntityDocument $entity
203198
*
204199
* @return bool
205200
*/
206-
public function equals( $target ) {
207-
if ( $this === $target ) {
201+
public function equals( EntityDocument $entity ) {
202+
if ( $this === $entity ) {
208203
return true;
209204
}
210205

211-
return $target instanceof self
212-
&& $this->dataTypeId === $target->dataTypeId
213-
&& $this->fingerprint->equals( $target->fingerprint )
214-
&& $this->statements->equals( $target->statements );
206+
return $entity instanceof self
207+
&& $this->dataTypeId === $entity->dataTypeId
208+
&& $this->fingerprint->equals( $entity->fingerprint )
209+
&& $this->statements->equals( $entity->statements );
215210
}
216211

217212
/**

0 commit comments

Comments
 (0)