Skip to content

Commit ed29c36

Browse files
Benestarthiemowmde
authored andcommitted
Add clear to list classes
This is needed as a replacement for users of the holder interfaces to remove all elements from one of the given list classes. Bug: T128363
1 parent d6a55f2 commit ed29c36

7 files changed

Lines changed: 58 additions & 0 deletions

File tree

RELEASE-NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* Removed `HashArray::indicesAreUpToDate`
1212
* Removed `HashArray::removeDuplicates`
1313
* Removed `$acceptDuplicates` feature from `HashArray`
14+
* Added `clear` to `TermList`, `AliasGroupList` and `StatementList`
1415

1516
## Version 6.3.1 (2016-11-30)
1617

src/Statement/StatementList.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,15 @@ public function filter( StatementFilter $filter ) {
341341
return $statementList;
342342
}
343343

344+
/**
345+
* Removes all statements from this list.
346+
*
347+
* @since 6.0
348+
*/
349+
public function clear() {
350+
$this->statements = [];
351+
}
352+
344353
/**
345354
* @see http://php.net/manual/en/language.oop5.cloning.php
346355
*

src/Term/AliasGroupList.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,4 +204,13 @@ public function toTextArray() {
204204
return $array;
205205
}
206206

207+
/**
208+
* Removes all alias groups from this list.
209+
*
210+
* @since 6.0
211+
*/
212+
public function clear() {
213+
$this->groups = [];
214+
}
215+
207216
}

src/Term/TermList.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,13 @@ public function hasTerm( Term $term ) {
187187
&& $this->terms[$term->getLanguageCode()]->equals( $term );
188188
}
189189

190+
/**
191+
* Removes all terms from this list.
192+
*
193+
* @since 6.0
194+
*/
195+
public function clear() {
196+
$this->terms = [];
197+
}
198+
190199
}

tests/unit/Statement/StatementListTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,4 +702,14 @@ public function testFilter() {
702702
);
703703
}
704704

705+
public function testClear() {
706+
$statement1 = $this->getStatement( 1, null );
707+
$statement2 = $this->getStatement( 2, null );
708+
$statements = new StatementList( $statement1, $statement2 );
709+
710+
$statements->clear();
711+
712+
$this->assertEquals( new StatementList(), $statements );
713+
}
714+
705715
}

tests/unit/Term/AliasGroupListTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,4 +383,14 @@ public function testToTextArray() {
383383
$this->assertEquals( $expected, $list->toTextArray() );
384384
}
385385

386+
public function testClear() {
387+
$list = new AliasGroupList();
388+
$list->setAliasesForLanguage( 'en', [ 'foo', 'baz' ] );
389+
$list->setAliasesForLanguage( 'de', [ 'bar' ] );
390+
391+
$list->clear();
392+
393+
$this->assertEquals( new AliasGroupList(), $list );
394+
}
395+
386396
}

tests/unit/Term/TermListTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,4 +396,14 @@ public function testGivenEmptyTerm_setTermRemovesExistingOne() {
396396
);
397397
}
398398

399+
public function testClear() {
400+
$list = new TermList();
401+
$list->setTextForLanguage( 'en', 'foo' );
402+
$list->setTextForLanguage( 'de', 'bar' );
403+
404+
$list->clear();
405+
406+
$this->assertEquals( new TermList(), $list );
407+
}
408+
399409
}

0 commit comments

Comments
 (0)