Thiemo Mättig (WMDE) has uploaded a new change for review.
https://gerrit.wikimedia.org/r/191016
Change subject: Drop unused code from deprecated Wikibase\Term class
......................................................................
Drop unused code from deprecated Wikibase\Term class
This class should not be used any more. This patch drops methods
(or makes fields and methods private) if they are not used any more
outside of tests.
Change-Id: I861ad8571f77814814fb63d7b2f06e6f4ac04df1
---
M lib/includes/Term.php
M lib/tests/phpunit/TermTest.php
2 files changed, 4 insertions(+), 198 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/16/191016/1
diff --git a/lib/includes/Term.php b/lib/includes/Term.php
index acf34a7..cf91e9f 100644
--- a/lib/includes/Term.php
+++ b/lib/includes/Term.php
@@ -27,19 +27,9 @@
const TYPE_DESCRIPTION = 'description';
/**
- * @since 0.2
- *
* @var array
*/
- protected $fields = array();
-
- protected static $fieldNames = array(
- 'entityType',
- 'entityId',
- 'termType',
- 'termLanguage',
- 'termText',
- );
+ private $fields = array();
/**
* @since 0.2
@@ -145,13 +135,11 @@
}
/**
- * @since 0.2
- *
* @param string $entityType
*
* @throws MWException
*/
- public function setEntityType( $entityType ) {
+ private function setEntityType( $entityType ) {
if ( !is_string( $entityType ) ) {
throw new MWException( 'Entity type code can only be a
string' );
}
@@ -169,14 +157,11 @@
}
/**
- * @since 0.2
- * @deprecated Please avoid using this.
- *
* @param int $id
*
* @throws MWException
*/
- public function setNumericId( $id ) {
+ private function setNumericId( $id ) {
if ( !is_int( $id ) ) {
throw new MWException( 'Numeric ID can only be an
integer' );
}
@@ -202,64 +187,6 @@
}
return null;
- }
-
- /**
- * Returns true if this Term object is equals to $that. This Term
object is considered
- * equal to $that if $that is also an instance of Term, and
$that->fields contains the
- * same values for the same fields as $this->fields.
- *
- * @param mixed $that The object to check for equality.
- *
- * @return bool If $that is equal to this Term object.
- */
- public function equals( $that ) {
- if ( $this === $that ) {
- return true;
- } else if ( !( $that instanceof self ) ) {
- return false;
- } else {
- if ( count( $this->fields ) != count( $that->fields ) )
{
- return false;
- }
-
- foreach ( $this->fields as $k => $v ) {
- if ( !isset( $that->fields[$k] ) ||
$that->fields[$k] !== $v ) {
- return false;
- }
- }
- }
-
- return true;
- }
-
- /**
- * Imposes an canonical but arbitrary order on Term objects.
- * Useful for sorting lists of terms for comparison.
- *
- * @param Term $a
- * @param Term $b
- *
- * @return int Returns 1 if $a is greater than $b, -1 if $b is greater
than $a, and 0 otherwise.
- */
- public static function compare( Term $a, Term $b ) {
- foreach ( self::$fieldNames as $n ) {
- if ( !isset( $a->fields[$n] ) ) {
- if ( isset( $b->fields[$n] ) ) {
- return -1;
- }
- } elseif ( !isset( $b->fields[$n] ) ) {
- if ( isset( $a->fields[$n] ) ) {
- return 1;
- }
- } elseif ( $a->fields[$n] > $b->fields[$n] ) {
- return 1;
- } elseif ( $a->fields[$n] < $b->fields[$n] ) {
- return -1;
- }
- }
-
- return 0;
}
}
diff --git a/lib/tests/phpunit/TermTest.php b/lib/tests/phpunit/TermTest.php
index af36a31..d68ff6a 100644
--- a/lib/tests/phpunit/TermTest.php
+++ b/lib/tests/phpunit/TermTest.php
@@ -75,128 +75,7 @@
$this->assertEquals( 'Foo', $term->getText(), "original must
stay the same when clone is modified" );
$clone = clone $term;
- $this->assertTrue( $term->equals( $clone ), "clone must be
equal to original" );
- }
-
- public function provideCompare() {
- $tests = array();
-
- $tests[] = array( // #0
- new Term(),
- new Term(),
- true
- );
-
- $term = new Term( array(
- 'entityType' => 'item',
- 'entityId' => 23,
- 'termType' => Term::TYPE_LABEL,
- 'termLanguage' => 'en',
- 'termText' => 'foo',
- ) );
-
- $other = clone $term;
- $tests[] = array( // #1
- $term,
- $other,
- true
- );
-
- $other = clone $term;
- $other->setText( 'bar' );
- $tests[] = array( // #2
- $term,
- $other,
- false
- );
-
- $other = clone $term;
- $other->setNumericId( 11 );
- $tests[] = array( // #3
- $term,
- $other,
- false
- );
-
- $other = clone $term;
- $other->setEntityType( 'property' );
- $tests[] = array( // #4
- $term,
- $other,
- false
- );
-
- $other = clone $term;
- $other->setLanguage( 'fr' );
- $tests[] = array( // #5
- $term,
- $other,
- false
- );
-
- $other = clone $term;
- $other->setType( Term::TYPE_DESCRIPTION );
- $tests[] = array( // #6
- $term,
- $other,
- false
- );
-
- return $tests;
- }
-
- /**
- * @dataProvider provideCompare
- * @depends testClone
- */
- public function testCompare( Term $a, Term $b, $equal ) {
- $ab = Term::compare( $a, $b );
- $ba = Term::compare( $b, $a );
-
- if ( $equal ) {
- $this->assertEquals( 0, $ab, "Comparison of equal terms
is expected to return 0" );
- $this->assertEquals( 0, $ba, "Comparison of equal terms
is expected to return 0" );
- } else {
- //NOTE: we don't know or care whether this is larger or
smaller
- $this->assertNotEquals( 0, $ab, "Comparison of unequal
terms is expected to not return 0" );
- $this->assertEquals( -$ab, $ba, "Comparing A to B
should return the inverse of comparing B to A" );
- }
- }
-
- public function provideEquals() {
- $tests = array(
- array( // #0
- new Term(),
- null,
- false
- ),
-
- array( // #1
- new Term(),
- false,
- false
- ),
-
- array( // #2
- new Term(),
- "",
- false
- ),
- );
-
- return array_merge( $tests, self::provideCompare() );
- }
-
- /**
- * @dataProvider provideEquals
- * @depends testClone
- */
- public function testEquals( Term $a, $b, $equal ) {
- $this->assertEquals( $equal, $a->equals( $b ) );
-
- if ( $b instanceof Term ) {
- $this->assertEquals( $equal, $b->equals( $a ) );
- }
+ $this->assertEquals( $term, $clone, "clone must be equal to
original" );
}
}
--
To view, visit https://gerrit.wikimedia.org/r/191016
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I861ad8571f77814814fb63d7b2f06e6f4ac04df1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits