jenkins-bot has submitted this change and it was merged.
Change subject: Require only required parameters in GeoCoordinateValue's
newFromArray
......................................................................
Require only required parameters in GeoCoordinateValue's newFromArray
Change-Id: Idea6d5395afdb2a32cd70ba389097c58718b6ba5
---
M DataValues/includes/values/GeoCoordinateValue.php
M DataValues/tests/phpunit/includes/values/GeoCoordinateValueTest.php
2 files changed, 14 insertions(+), 11 deletions(-)
Approvals:
Tobias Gritschacher: Looks good to me, approved
jenkins-bot: Verified
diff --git a/DataValues/includes/values/GeoCoordinateValue.php
b/DataValues/includes/values/GeoCoordinateValue.php
index d1e4fb8..61eec4d 100644
--- a/DataValues/includes/values/GeoCoordinateValue.php
+++ b/DataValues/includes/values/GeoCoordinateValue.php
@@ -81,12 +81,12 @@
* @param float|int $latitude
* @param float|int $longitude
* @param float|int|null $altitude
- * param float|int|null $precision
+ * @param float|int|null $precision
* @param string|null $globe
*
* @throws IllegalValueException
*/
- public function __construct( $latitude, $longitude, $altitude = null,
$precision = null, $globe = 'http://www.wikidata.org/entity/Q2' ) {
+ public function __construct( $latitude, $longitude, $altitude = null,
$precision = null, $globe = null ) {
// TODO: validate those values!
if ( is_int( $latitude ) ) {
$latitude = (float)$latitude;
@@ -128,7 +128,7 @@
$this->longitude = $longitude;
$this->altitude = $altitude;
$this->precision = $precision;
- $this->globe = $globe;
+ $this->globe = ( is_null( $globe ) ) ?
'http://www.wikidata.org/entity/Q2' : $globe;
}
/**
@@ -278,14 +278,14 @@
* @throws IllegalValueException
*/
public static function newFromArray( $data ) {
- self::requireArrayFields( $data, array( 'latitude',
'longitude', 'altitude', 'precision', 'globe' ) );
+ self::requireArrayFields( $data, array( 'latitude', 'longitude'
) );
return new static(
$data['latitude'],
$data['longitude'],
- $data['altitude'],
- $data['precision'],
- $data['globe']
+ ( isset( $data['altitude'] ) ) ? $data['altitude'] :
null,
+ ( isset( $data['precision'] ) ) ? $data['precision'] :
null,
+ ( isset( $data['globe'] ) ) ? $data['globe'] : null
);
}
diff --git
a/DataValues/tests/phpunit/includes/values/GeoCoordinateValueTest.php
b/DataValues/tests/phpunit/includes/values/GeoCoordinateValueTest.php
index 33a3d4a..99e3a42 100644
--- a/DataValues/tests/phpunit/includes/values/GeoCoordinateValueTest.php
+++ b/DataValues/tests/phpunit/includes/values/GeoCoordinateValueTest.php
@@ -112,7 +112,7 @@
// #42
$argLists[] = array( true, 42, 4.2, 9000.1, null,
'http://www.wikidata.org/entity/Q2' );
- $argLists[] = array( true, 42, 4.2, 9000.1, null, null );
+ $argLists[] = array( true, 42, 4.2, 9000.1, null );
$argLists[] = array( true, 4.2, 42, 9000.1, null, 'terminus' );
$argLists[] = array( true, 4.2, 42, 0, null, "Schar's World" );
$argLists[] = array( true, -42, -4.2, -9000.1, null,
'coruscant' );
@@ -176,12 +176,15 @@
* @param array $arguments
*/
public function testGetGlobe( GeoCoordinateValue $geoCoord, array
$arguments ) {
- $expected = array_key_exists( 4, $arguments ) ? $arguments[4] :
'http://www.wikidata.org/entity/Q2';
+ $expected = array_key_exists( 4, $arguments )
+ ? $arguments[4]
+ : 'http://www.wikidata.org/entity/Q2';
+
$actual = $geoCoord->getGlobe();
$this->assertTrue(
- is_null( $actual ) || is_string( $actual ),
- 'getGlobe should return a string or null'
+ is_string( $actual ),
+ 'getGlobe should return a string'
);
$this->assertEquals( $expected, $actual );
--
To view, visit https://gerrit.wikimedia.org/r/68619
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Idea6d5395afdb2a32cd70ba389097c58718b6ba5
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/DataValues
Gerrit-Branch: master
Gerrit-Owner: Henning Snater <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits