Skip to content

Commit

Permalink
Globe default value
Browse files Browse the repository at this point in the history
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
  • Loading branch information
thiemowmde authored and JeroenDeDauw committed Jul 18, 2014
1 parent 746dab8 commit 6981ea0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 28 deletions.
36 changes: 10 additions & 26 deletions src/DataValues/GlobeCoordinateValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -31,30 +27,30 @@ class GlobeCoordinateValue extends DataValueObject {
/**
* IRI of the globe on which the location resides.
*
* @since 0.1
*
* @var string
*/
protected $globe;

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 ) {
Expand All @@ -72,8 +68,6 @@ protected function assertIsGlobe( $globe ) {
/**
* @see Serializable::serialize
*
* @since 0.1
*
* @return string
*/
public function serialize() {
Expand All @@ -83,8 +77,6 @@ public function serialize() {
/**
* @see Serializable::unserialize
*
* @since 0.1
*
* @param string $value
*
* @return GlobeCoordinateValue
Expand All @@ -103,8 +95,6 @@ public function unserialize( $value ) {
/**
* @see DataValue::getType
*
* @since 0.1
*
* @return string
*/
public static function getType() {
Expand All @@ -114,8 +104,6 @@ public static function getType() {
/**
* @see DataValue::getSortKey
*
* @since 0.1
*
* @return float
*/
public function getSortKey() {
Expand Down Expand Up @@ -148,8 +136,6 @@ public function getLongitude() {
* Returns the text.
* @see DataValue::getValue
*
* @since 0.1
*
* @return GlobeCoordinateValue
*/
public function getValue() {
Expand All @@ -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
*
Expand All @@ -190,8 +176,6 @@ public function getGlobe() {
/**
* @see DataValue::getArrayValue
*
* @since 0.1
*
* @return array
*/
public function getArrayValue() {
Expand Down
4 changes: 2 additions & 2 deletions tests/DataValues/GlobeCoordinateValueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 );

Expand Down Expand Up @@ -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;

Expand Down

1 comment on commit 6981ea0

@filbertkm
Copy link
Contributor

Choose a reason for hiding this comment

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

looks reasonable but is appears to be a breaking change for api users (if they forget to specify the globe, then a default is applied)?

imho, needs to be documented, announced, etc. once wikibase uses this code.

Please sign in to comment.