From 6981ea0974941b306a6c3da62aeee683faf40a56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thiemo=20M=C3=A4ttig?= Date: Sun, 15 Jun 2014 13:06:25 +0200 Subject: [PATCH] Globe default value Before: new GlobeCoordinateValue( $latLang, $precision ) was possible but new GlobeCoordinateValue( $latLang, $precision, null ) failed. Doesn't make much sense if you think about, especially in terms of deserialization. After: Both calls use the default value. Bug: 66632 --- src/DataValues/GlobeCoordinateValue.php | 36 ++++++------------- tests/DataValues/GlobeCoordinateValueTest.php | 4 +-- 2 files changed, 12 insertions(+), 28 deletions(-) diff --git a/src/DataValues/GlobeCoordinateValue.php b/src/DataValues/GlobeCoordinateValue.php index e99e954..7d4ffcd 100644 --- a/src/DataValues/GlobeCoordinateValue.php +++ b/src/DataValues/GlobeCoordinateValue.php @@ -13,16 +13,12 @@ class GlobeCoordinateValue extends DataValueObject { /** - * @since 0.1 - * * @var LatLongValue */ protected $latLang; /** - * The precision of the coordinate. - * - * @since 0.1 + * The precision of the coordinate in degrees, e.g. 0.01. * * @var float|int|null */ @@ -31,8 +27,6 @@ class GlobeCoordinateValue extends DataValueObject { /** * IRI of the globe on which the location resides. * - * @since 0.1 - * * @var string */ protected $globe; @@ -40,21 +34,23 @@ class GlobeCoordinateValue extends DataValueObject { const GLOBE_EARTH = 'http://www.wikidata.org/entity/Q2'; /** - * @since 0.1 - * * @param LatLongValue $latLang - * @param float|int|null $precision - * @param string $globe IRI, defaults to 'http://www.wikidata.org/entity/Q2'. + * @param float|int|null $precision in degrees, e.g. 0.01. + * @param string|null $globe IRI, defaults to 'http://www.wikidata.org/entity/Q2'. * * @throws IllegalValueException */ - public function __construct( LatLongValue $latLang, $precision, $globe = self::GLOBE_EARTH ) { + public function __construct( LatLongValue $latLang, $precision, $globe = null ) { + if ( $globe === null ) { + $globe = self::GLOBE_EARTH; + } + $this->assertIsPrecision( $precision ); $this->assertIsGlobe( $globe ); $this->latLang = $latLang; $this->precision = $precision; - $this->globe = $globe; + $this->globe = $globe; } protected function assertIsPrecision( $precision ) { @@ -72,8 +68,6 @@ protected function assertIsGlobe( $globe ) { /** * @see Serializable::serialize * - * @since 0.1 - * * @return string */ public function serialize() { @@ -83,8 +77,6 @@ public function serialize() { /** * @see Serializable::unserialize * - * @since 0.1 - * * @param string $value * * @return GlobeCoordinateValue @@ -103,8 +95,6 @@ public function unserialize( $value ) { /** * @see DataValue::getType * - * @since 0.1 - * * @return string */ public static function getType() { @@ -114,8 +104,6 @@ public static function getType() { /** * @see DataValue::getSortKey * - * @since 0.1 - * * @return float */ public function getSortKey() { @@ -148,8 +136,6 @@ public function getLongitude() { * Returns the text. * @see DataValue::getValue * - * @since 0.1 - * * @return GlobeCoordinateValue */ public function getValue() { @@ -166,7 +152,7 @@ public function getLatLong() { } /** - * Returns the precision of the coordinate. + * Returns the precision of the coordinate in degrees, e.g. 0.01. * * @since 0.1 * @@ -190,8 +176,6 @@ public function getGlobe() { /** * @see DataValue::getArrayValue * - * @since 0.1 - * * @return array */ public function getArrayValue() { diff --git a/tests/DataValues/GlobeCoordinateValueTest.php b/tests/DataValues/GlobeCoordinateValueTest.php index 1f56458..9db418a 100644 --- a/tests/DataValues/GlobeCoordinateValueTest.php +++ b/tests/DataValues/GlobeCoordinateValueTest.php @@ -45,6 +45,7 @@ public function validConstructorArgumentsProvider() { $argLists[] = array( new LatLongValue( 4.2, 4.2 ), 1, 'terminus' ); $argLists[] = array( new LatLongValue( 4.2, 4.2 ), 1, "Schar's World" ); $argLists[] = array( new LatLongValue( 4.2, 4.2 ), 1, 'coruscant' ); + $argLists[] = array( new LatLongValue( 4.2, 4.2 ), 1, null ); $argLists[] = array( new LatLongValue( 4.2, 4.2 ), null ); return $argLists; @@ -58,7 +59,6 @@ public function invalidConstructorArgumentsProvider() { $argLists[] = array( new LatLongValue( 4.2, 4.2 ), array( 1 ) ); $argLists[] = array( new LatLongValue( 4.2, 4.2 ), '1' ); - $argLists[] = array( new LatLongValue( 4.2, 4.2 ), 1, null ); $argLists[] = array( new LatLongValue( 4.2, 4.2 ), 1, array( 1 ) ); $argLists[] = array( new LatLongValue( 4.2, 4.2 ), 1, 1 ); @@ -109,7 +109,7 @@ public function testGetPrecision( GlobeCoordinateValue $globeCoordinate, array $ * @param array $arguments */ public function testGetGlobe( GlobeCoordinateValue $globeCoordinate, array $arguments ) { - $expected = array_key_exists( 2, $arguments ) + $expected = isset( $arguments[2] ) ? $arguments[2] : GlobeCoordinateValue::GLOBE_EARTH;