diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index bdc758d7..2b4eb79a 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -15,6 +15,7 @@ * `getByLangauge` now throws an `OutOfBoundsException`. * `removeByLanguage` does nothing for invalid values. * `hasTermForLanguage` and `hasGroupForLangauge` return false instead. +* Added `clear` to `TermList`, `AliasGroupList` and `StatementList` ## Version 5.1.0 (2016-03-08) diff --git a/src/Statement/StatementList.php b/src/Statement/StatementList.php index 11fe50ef..82d06c56 100644 --- a/src/Statement/StatementList.php +++ b/src/Statement/StatementList.php @@ -325,6 +325,15 @@ public function filter( StatementFilter $filter ) { return $statementList; } + /** + * Removes all statements from this list. + * + * @since 6.0 + */ + public function clear() { + $this->statements = array(); + } + /** * @see http://php.net/manual/en/language.oop5.cloning.php * diff --git a/src/Term/AliasGroupList.php b/src/Term/AliasGroupList.php index d991b92b..3a85ea21 100644 --- a/src/Term/AliasGroupList.php +++ b/src/Term/AliasGroupList.php @@ -204,4 +204,13 @@ public function toTextArray() { return $array; } + /** + * Removes all alias groups from this list. + * + * @since 6.0 + */ + public function clear() { + $this->groups = array(); + } + } diff --git a/src/Term/TermList.php b/src/Term/TermList.php index 8c0da46d..b8e12122 100644 --- a/src/Term/TermList.php +++ b/src/Term/TermList.php @@ -187,4 +187,13 @@ public function hasTerm( Term $term ) { && $this->terms[$term->getLanguageCode()]->equals( $term ); } + /** + * Removes all terms from this list. + * + * @since 6.0 + */ + public function clear() { + $this->terms = array(); + } + } diff --git a/tests/unit/Statement/StatementListTest.php b/tests/unit/Statement/StatementListTest.php index 262be14a..2002b76e 100644 --- a/tests/unit/Statement/StatementListTest.php +++ b/tests/unit/Statement/StatementListTest.php @@ -650,4 +650,14 @@ public function testFilter() { ); } + public function testClear() { + $statement1 = $this->getStatement( 1, null ); + $statement2 = $this->getStatement( 2, null ); + $statements = new StatementList( $statement1, $statement2 ); + + $statements->clear(); + + $this->assertEquals( new StatementList(), $statements ); + } + } diff --git a/tests/unit/Term/AliasGroupListTest.php b/tests/unit/Term/AliasGroupListTest.php index a4f9a09a..44642283 100644 --- a/tests/unit/Term/AliasGroupListTest.php +++ b/tests/unit/Term/AliasGroupListTest.php @@ -383,4 +383,14 @@ public function testToTextArray() { $this->assertEquals( $expected, $list->toTextArray() ); } + public function testClear() { + $list = new AliasGroupList(); + $list->setAliasesForLanguage( 'en', array( 'foo', 'baz' ) ); + $list->setAliasesForLanguage( 'de', array( 'bar' ) ); + + $list->clear(); + + $this->assertEquals( new AliasGroupList(), $list ); + } + } diff --git a/tests/unit/Term/TermListTest.php b/tests/unit/Term/TermListTest.php index 96854e15..48ee6ebd 100644 --- a/tests/unit/Term/TermListTest.php +++ b/tests/unit/Term/TermListTest.php @@ -397,4 +397,14 @@ public function testGivenEmptyTerm_setTermRemovesExistingOne() { ); } + public function testClear() { + $list = new TermList(); + $list->setTextForLanguage( 'en', 'foo' ); + $list->setTextForLanguage( 'de', 'bar' ); + + $list->clear(); + + $this->assertEquals( new TermList(), $list ); + } + }