Skip to content

Commit 09da033

Browse files
author
Daniel Kinzler
committed
Merge pull request #621 from wmde/equalsRevert
Revert unnecessary breaking change to Item::equals Merging this for now to unblock the 5.0 release. I still think we shouldn't use Comparable here, since it's useless without support for generics. But let's keep that discussion for the 6.0 release.
2 parents 5923189 + ae41850 commit 09da033

4 files changed

Lines changed: 21 additions & 19 deletions

File tree

RELEASE-NOTES.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
* Added `getIterator` method.
1818
* Removed `ReferenceList::removeDuplicates`.
1919
* `ReferenceList::addReference` now throws an `InvalidArgumentException` for negative indices.
20-
* `Entity` no longer implements `Comparable`
21-
* Added `EntityDocument::equals`
20+
* `EntityDocument` now implements `Comparable`.
2221

2322
## Version 4.4.0 (2016-01-20)
2423

src/Entity/EntityDocument.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Wikibase\DataModel\Entity;
44

5+
use Comparable;
56
use InvalidArgumentException;
67

78
/**
@@ -14,7 +15,7 @@
1415
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
1516
* @author Bene* < benestar.wikimedia@gmail.com >
1617
*/
17-
interface EntityDocument {
18+
interface EntityDocument extends Comparable {
1819

1920
/**
2021
* Returns the id of the entity or null if it does not have one.
@@ -54,15 +55,17 @@ public function setId( $id );
5455
public function isEmpty();
5556

5657
/**
58+
* @see Comparable::equals
59+
*
5760
* Two entities are considered equal if they are of the same
5861
* type and have the same value. The value does not include
5962
* the id, so entities with the same value but different id
6063
* are considered equal.
6164
*
62-
* @param EntityDocument $entity
65+
* @param mixed $target
6366
*
6467
* @return bool
6568
*/
66-
public function equals( EntityDocument $entity );
69+
public function equals( $target );
6770

6871
}

src/Entity/Item.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -304,19 +304,19 @@ public function setStatements( StatementList $statements ) {
304304
*
305305
* @since 0.1
306306
*
307-
* @param EntityDocument $entity
307+
* @param mixed $target
308308
*
309309
* @return bool
310310
*/
311-
public function equals( EntityDocument $entity ) {
312-
if ( $this === $entity ) {
311+
public function equals( $target ) {
312+
if ( $this === $target ) {
313313
return true;
314314
}
315315

316-
return $entity instanceof self
317-
&& $this->fingerprint->equals( $entity->fingerprint )
318-
&& $this->siteLinks->equals( $entity->siteLinks )
319-
&& $this->statements->equals( $entity->statements );
316+
return $target instanceof self
317+
&& $this->fingerprint->equals( $target->fingerprint )
318+
&& $this->siteLinks->equals( $target->siteLinks )
319+
&& $this->statements->equals( $target->statements );
320320
}
321321

322322
}

src/Entity/Property.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -194,19 +194,19 @@ public static function newFromType( $dataTypeId ) {
194194
*
195195
* @since 0.1
196196
*
197-
* @param EntityDocument $entity
197+
* @param mixed $target
198198
*
199199
* @return bool
200200
*/
201-
public function equals( EntityDocument $entity ) {
202-
if ( $this === $entity ) {
201+
public function equals( $target ) {
202+
if ( $this === $target ) {
203203
return true;
204204
}
205205

206-
return $entity instanceof self
207-
&& $this->dataTypeId === $entity->dataTypeId
208-
&& $this->fingerprint->equals( $entity->fingerprint )
209-
&& $this->statements->equals( $entity->statements );
206+
return $target instanceof self
207+
&& $this->dataTypeId === $target->dataTypeId
208+
&& $this->fingerprint->equals( $target->fingerprint )
209+
&& $this->statements->equals( $target->statements );
210210
}
211211

212212
/**

0 commit comments

Comments
 (0)