Skip to content

Commit 90ec73d

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 5e642e3 commit 90ec73d

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
@@ -15,6 +15,7 @@
1515
* `getByLangauge` now throws an `OutOfBoundsException`.
1616
* `removeByLanguage` does nothing for invalid values.
1717
* `hasTermForLanguage` and `hasGroupForLangauge` return false instead.
18+
* Added `clear` to `TermList`, `AliasGroupList` and `StatementList`
1819

1920
## Version 5.1.0 (2016-03-08)
2021

src/Statement/StatementList.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,15 @@ public function filter( StatementFilter $filter ) {
325325
return $statementList;
326326
}
327327

328+
/**
329+
* Removes all statements from this list.
330+
*
331+
* @since 6.0
332+
*/
333+
public function clear() {
334+
$this->statements = array();
335+
}
336+
328337
/**
329338
* @see http://php.net/manual/en/language.oop5.cloning.php
330339
*

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 = array();
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 = array();
197+
}
198+
190199
}

tests/unit/Statement/StatementListTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,4 +650,14 @@ public function testFilter() {
650650
);
651651
}
652652

653+
public function testClear() {
654+
$statement1 = $this->getStatement( 1, null );
655+
$statement2 = $this->getStatement( 2, null );
656+
$statements = new StatementList( $statement1, $statement2 );
657+
658+
$statements->clear();
659+
660+
$this->assertEquals( new StatementList(), $statements );
661+
}
662+
653663
}

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', array( 'foo', 'baz' ) );
389+
$list->setAliasesForLanguage( 'de', array( '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
@@ -397,4 +397,14 @@ public function testGivenEmptyTerm_setTermRemovesExistingOne() {
397397
);
398398
}
399399

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

0 commit comments

Comments
 (0)