Skip to content

Commit 4de9629

Browse files
Benestarthiemowmde
authored andcommitted
Remove clear from Entity, Item and Property
New instances should be created instead of clearing an existing Entity. The only real usecase for this seems to be the clear=true parameter in the wbeditentity api module. Property::clear even had a bug in that it didn't clear the statements but only the fingerprint.
1 parent 59ec644 commit 4de9629

4 files changed

Lines changed: 0 additions & 59 deletions

File tree

src/Entity/Item.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -310,18 +310,6 @@ public function isEmpty() {
310310
&& $this->siteLinks->isEmpty();
311311
}
312312

313-
/**
314-
* Removes all content from the Item.
315-
* The id is not part of the content.
316-
*
317-
* @since 0.1
318-
*/
319-
public function clear() {
320-
$this->fingerprint = new Fingerprint();
321-
$this->siteLinks = new SiteLinkList();
322-
$this->statements = new StatementList();
323-
}
324-
325313
/**
326314
* @since 1.0
327315
*

src/Entity/Property.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -263,17 +263,6 @@ public function isEmpty() {
263263
&& $this->statements->isEmpty();
264264
}
265265

266-
/**
267-
* Removes all content from the Property.
268-
* The id and the type are not part of the content.
269-
*
270-
* @since 0.1
271-
*/
272-
public function clear() {
273-
$this->fingerprint = new Fingerprint();
274-
$this->statements = new StatementList();
275-
}
276-
277266
/**
278267
* @since 1.1
279268
*

tests/unit/Entity/ItemTest.php

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -231,23 +231,6 @@ private function newStatement() {
231231
return $statement;
232232
}
233233

234-
public function testClearRemovesAllButId() {
235-
$item = new Item( new ItemId( 'Q42' ) );
236-
$item->getFingerprint()->setLabel( 'en', 'foo' );
237-
$item->getSiteLinkList()->addNewSiteLink( 'enwiki', 'Foo' );
238-
$item->getStatements()->addStatement( $this->newStatement() );
239-
240-
$item->clear();
241-
242-
$this->assertEquals( new ItemId( 'Q42' ), $item->getId() );
243-
$this->assertTrue( $item->getFingerprint()->isEmpty() );
244-
$this->assertTrue( $item->getLabels()->isEmpty() );
245-
$this->assertTrue( $item->getDescriptions()->isEmpty() );
246-
$this->assertTrue( $item->getAliasGroups()->isEmpty() );
247-
$this->assertTrue( $item->getSiteLinkList()->isEmpty() );
248-
$this->assertTrue( $item->getStatements()->isEmpty() );
249-
}
250-
251234
public function testEmptyConstructor() {
252235
$item = new Item();
253236

@@ -282,13 +265,6 @@ public function testSetStatements() {
282265
$this->assertTrue( $item->getStatements()->isEmpty() );
283266
}
284267

285-
public function testGetStatementsReturnsCorrectTypeAfterClear() {
286-
$item = new Item();
287-
$item->clear();
288-
289-
$this->assertTrue( $item->getStatements()->isEmpty() );
290-
}
291-
292268
public function equalsProvider() {
293269
$firstItem = new Item();
294270
$firstItem->getStatements()->addNewStatement( new PropertyNoValueSnak( 42 ) );

tests/unit/Entity/PropertyTest.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,6 @@ public function testPropertyWithFingerprintIsNotEmpty() {
112112
$this->assertFalse( $property->isEmpty() );
113113
}
114114

115-
public function testClearRemovesAllButId() {
116-
$property = Property::newFromType( 'string' );
117-
$property->setId( 42 );
118-
$property->getFingerprint()->setLabel( 'en', 'foo' );
119-
$property->getStatements()->addNewStatement( new PropertyNoValueSnak( 1 ) );
120-
121-
$property->clear();
122-
123-
$this->assertEquals( new PropertyId( 'P42' ), $property->getId() );
124-
$this->assertTrue( $property->isEmpty() );
125-
}
126-
127115
public function testGetStatementsReturnsEmptyListForEmptyProperty() {
128116
$property = Property::newFromType( 'string' );
129117

0 commit comments

Comments
 (0)