Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add clear to list classes #649

Merged
merged 1 commit into from
Mar 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* Removed `HashArray::indicesAreUpToDate`
* Removed `HashArray::removeDuplicates`
* Removed `$acceptDuplicates` feature from `HashArray`
* Added `clear` to `TermList`, `AliasGroupList` and `StatementList`

## Version 6.3.1 (2016-11-30)

Expand Down
9 changes: 9 additions & 0 deletions src/Statement/StatementList.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,15 @@ public function filter( StatementFilter $filter ) {
return $statementList;
}

/**
* Removes all statements from this list.
*
* @since 6.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should have been 7.0 (or maybe 6.4) I guess

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Fixed in #719.

*/
public function clear() {
$this->statements = [];
}

/**
* @see http://php.net/manual/en/language.oop5.cloning.php
*
Expand Down
9 changes: 9 additions & 0 deletions src/Term/AliasGroupList.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,13 @@ public function toTextArray() {
return $array;
}

/**
* Removes all alias groups from this list.
*
* @since 6.0
*/
public function clear() {
$this->groups = [];
}

}
9 changes: 9 additions & 0 deletions src/Term/TermList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
}

}
10 changes: 10 additions & 0 deletions tests/unit/Statement/StatementListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -702,4 +702,14 @@ public function testFilter() {
);
}

public function testClear() {
$statement1 = $this->getStatement( 'P1', null );
$statement2 = $this->getStatement( 'P2', null );
$statements = new StatementList( $statement1, $statement2 );

$statements->clear();

$this->assertEquals( new StatementList(), $statements );
}

}
10 changes: 10 additions & 0 deletions tests/unit/Term/AliasGroupListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,4 +383,14 @@ public function testToTextArray() {
$this->assertEquals( $expected, $list->toTextArray() );
}

public function testClear() {
$list = new AliasGroupList();
$list->setAliasesForLanguage( 'en', [ 'foo', 'baz' ] );
$list->setAliasesForLanguage( 'de', [ 'bar' ] );

$list->clear();

$this->assertEquals( new AliasGroupList(), $list );
}

}
10 changes: 10 additions & 0 deletions tests/unit/Term/TermListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,4 +396,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 );
}

}