Skip to content

Commit 9e8868c

Browse files
committed
Revert unnecesarry breaking change to Item::equals
1 parent 59061d5 commit 9e8868c

4 files changed

Lines changed: 29 additions & 31 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: 2 additions & 13 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.
@@ -53,16 +54,4 @@ public function setId( $id );
5354
*/
5455
public function isEmpty();
5556

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

src/Entity/Item.php

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

302302
/**
303-
* @see EntityDocument::equals
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.
304309
*
305310
* @since 0.1
306311
*
307-
* @param EntityDocument $entity
312+
* @param mixed $target
308313
*
309314
* @return bool
310315
*/
311-
public function equals( EntityDocument $entity ) {
312-
if ( $this === $entity ) {
316+
public function equals( $target ) {
317+
if ( $this === $target ) {
313318
return true;
314319
}
315320

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

322327
}

src/Entity/Property.php

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

192192
/**
193-
* @see EntityDocument::equals
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.
194199
*
195200
* @since 0.1
196201
*
197-
* @param EntityDocument $entity
202+
* @param mixed $target
198203
*
199204
* @return bool
200205
*/
201-
public function equals( EntityDocument $entity ) {
202-
if ( $this === $entity ) {
206+
public function equals( $target ) {
207+
if ( $this === $target ) {
203208
return true;
204209
}
205210

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

212217
/**

0 commit comments

Comments
 (0)