Jeroen De Dauw has submitted this change and it was merged.

Change subject: Introduce IllegalValueException
......................................................................


Introduce IllegalValueException

Change-Id: Ib7d85555748630a367b1f79a17ab02490d00ba26
---
M DataValues/DataValues.classes.php
A DataValues/includes/IllegalValueException.php
M DataValues/includes/values/BooleanValue.php
M DataValues/includes/values/GeoCoordinateValue.php
M DataValues/includes/values/IriValue.php
M DataValues/includes/values/MonolingualTextValue.php
M DataValues/includes/values/MultilingualTextValue.php
M DataValues/includes/values/NumberValue.php
M DataValues/includes/values/QuantityValue.php
M DataValues/includes/values/StringValue.php
M DataValues/includes/values/TimeValue.php
M DataValues/includes/values/UnknownValue.php
M DataValues/tests/phpunit/includes/values/TimeValueTest.php
13 files changed, 90 insertions(+), 73 deletions(-)

Approvals:
  Jeroen De Dauw: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/DataValues/DataValues.classes.php 
b/DataValues/DataValues.classes.php
index d7cce09..d364ef7 100644
--- a/DataValues/DataValues.classes.php
+++ b/DataValues/DataValues.classes.php
@@ -42,6 +42,8 @@
        'DataValues\DataValueFactory' => 'includes/DataValueFactory.php',
        'DataValues\DataValueObject' => 'includes/DataValueObject.php',
 
+       'DataValues\IllegalValueException' => 
'includes/IllegalValueException.php',
+
        'Comparable' => 'includes/Comparable.php',
        'Copyable' => 'includes/Copyable.php',
        'Hashable' => 'includes/Hashable.php',
diff --git a/DataValues/includes/IllegalValueException.php 
b/DataValues/includes/IllegalValueException.php
new file mode 100644
index 0000000..e166458
--- /dev/null
+++ b/DataValues/includes/IllegalValueException.php
@@ -0,0 +1,39 @@
+<?php
+ /**
+ *
+ * Copyright © 07.06.13 by the authors listed below.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @license GPL 2+
+ * @file
+ *
+ * @author Daniel Kinzler
+ */
+
+
+namespace DataValues;
+
+
+use InvalidArgumentException;
+
+/**
+ * Class IllegalValueException
+ * @package DataValues
+ */
+class IllegalValueException extends InvalidArgumentException {
+
+}
\ No newline at end of file
diff --git a/DataValues/includes/values/BooleanValue.php 
b/DataValues/includes/values/BooleanValue.php
index 91e1ddc..cf914ab 100644
--- a/DataValues/includes/values/BooleanValue.php
+++ b/DataValues/includes/values/BooleanValue.php
@@ -2,8 +2,6 @@
 
 namespace DataValues;
 
-use InvalidArgumentException;
-
 /**
  * Class representing a boolean value.
  *
@@ -44,11 +42,11 @@
         *
         * @param string $value
         *
-        * @throws InvalidArgumentException
+        * @throws IllegalValueException
         */
        public function __construct( $value ) {
                if ( !is_bool( $value ) ) {
-                       throw new InvalidArgumentException( 'Can only construct 
BooleanValue from booleans' );
+                       throw new IllegalValueException( 'Can only construct 
BooleanValue from booleans' );
                }
 
                $this->value = $value;
diff --git a/DataValues/includes/values/GeoCoordinateValue.php 
b/DataValues/includes/values/GeoCoordinateValue.php
index c574b9b..bbfa5bd 100644
--- a/DataValues/includes/values/GeoCoordinateValue.php
+++ b/DataValues/includes/values/GeoCoordinateValue.php
@@ -2,8 +2,6 @@
 
 namespace DataValues;
 
-use InvalidArgumentException;
-
 /**
  * Class representing a geographical coordinate value.
  *
@@ -86,7 +84,7 @@
         * @param string|null $globe
         * @param float|int|null $precision
         *
-        * @throws InvalidArgumentException
+        * @throws IllegalValueException
         */
        public function __construct( $latitude, $longitude, $altitude = null, 
$globe = 'http://www.wikidata.org/entity/Q2', $precision = null ) {
                // TODO: validate those values!
@@ -107,23 +105,23 @@
                }
 
                if ( !is_float( $latitude ) ) {
-                       throw new InvalidArgumentException( 'Can only construct 
GeoCoordinateValue with a numeric latitude' );
+                       throw new IllegalValueException( 'Can only construct 
GeoCoordinateValue with a numeric latitude' );
                }
 
                if ( !is_float( $longitude ) ) {
-                       throw new InvalidArgumentException( 'Can only construct 
GeoCoordinateValue with a numeric longitude' );
+                       throw new IllegalValueException( 'Can only construct 
GeoCoordinateValue with a numeric longitude' );
                }
 
                if ( $altitude !== null && !is_float( $altitude ) ) {
-                       throw new InvalidArgumentException( 'Can only construct 
GeoCoordinateValue with a numeric altitude' );
+                       throw new IllegalValueException( 'Can only construct 
GeoCoordinateValue with a numeric altitude' );
                }
 
                if ( $precision !== null && !is_float( $precision ) ) {
-                       throw new InvalidArgumentException( 'Can only construct 
GeoCoordinateValue with a numeric precision' );
+                       throw new IllegalValueException( 'Can only construct 
GeoCoordinateValue with a numeric precision' );
                }
 
                if ( !is_string( $globe ) && $globe !== null ) {
-                       throw new InvalidArgumentException( 'Can only construct 
GeoCoordinateValue with a string or null globe parameter' );
+                       throw new IllegalValueException( 'Can only construct 
GeoCoordinateValue with a string or null globe parameter' );
                }
 
                $this->latitude = $latitude;
@@ -152,7 +150,7 @@
         * @param string $value
         *
         * @return GeoCoordinateValue
-        * @throws InvalidArgumentException
+        * @throws IllegalValueException
         */
        public function unserialize( $value ) {
                list( $latitude, $longitude, $altitude, $globe, $precision ) = 
json_decode( $value );
diff --git a/DataValues/includes/values/IriValue.php 
b/DataValues/includes/values/IriValue.php
index 804a965..a30ef6a 100644
--- a/DataValues/includes/values/IriValue.php
+++ b/DataValues/includes/values/IriValue.php
@@ -2,8 +2,6 @@
 
 namespace DataValues;
 
-use InvalidArgumentException;
-
 /**
  * Class representing a IRI value.
  *
@@ -88,21 +86,21 @@
         * @param string $query
         * @param string $fragment
         *
-        * @throws InvalidArgumentException
+        * @throws IllegalValueException
         */
        public function __construct( $scheme, $hierarchicalPart, $query = '', 
$fragment = '' ) {
                foreach ( func_get_args() as $value ) {
                        if ( !is_string( $value ) ) {
-                               throw new InvalidArgumentException( 'Can only 
construct IriValue from strings' );
+                               throw new IllegalValueException( 'Can only 
construct IriValue from strings' );
                        }
                }
 
                if ( $scheme === '' || preg_match( '/[^a-zA-Z]/u', $scheme ) ) {
-                       throw new InvalidArgumentException( "Illegal URI scheme 
'$scheme'." );
+                       throw new IllegalValueException( "Illegal URI scheme 
'$scheme'." );
                }
 
                if ( $hierarchicalPart === '' ) {
-                       throw new InvalidArgumentException( "Illegal URI 
hierarchical part '$hierarchicalPart'." );
+                       throw new IllegalValueException( "Illegal URI 
hierarchical part '$hierarchicalPart'." );
                }
 
                $this->scheme = $scheme;
@@ -225,17 +223,17 @@
         * @param string $serialization
         *
         * @return array
-        * @throws InvalidArgumentException
+        * @throws IllegalValueException
         */
        public static function getIriParts( $serialization ) {
                if ( !is_string( $serialization ) ) {
-                       throw new InvalidArgumentException( 
'IriValue::getIriParts expects a string value' );
+                       throw new IllegalValueException( 'IriValue::getIriParts 
expects a string value' );
                }
 
                $parts = explode( ':', $serialization, 2 ); // try to split 
"schema:rest"
 
                if ( count( $parts ) === 1 ) {
-                       throw new InvalidArgumentException( "Unserialization 
failed: the string \"$serialization\" is no valid URI." );
+                       throw new IllegalValueException( "Unserialization 
failed: the string \"$serialization\" is no valid URI." );
                }
 
                $scheme = $parts[0];
diff --git a/DataValues/includes/values/MonolingualTextValue.php 
b/DataValues/includes/values/MonolingualTextValue.php
index 2602021..c609653 100644
--- a/DataValues/includes/values/MonolingualTextValue.php
+++ b/DataValues/includes/values/MonolingualTextValue.php
@@ -2,8 +2,6 @@
 
 namespace DataValues;
 
-use InvalidArgumentException;
-
 /**
  * Class representing a monolingual text value.
  *
@@ -56,18 +54,18 @@
         * @param string $languageCode
         * @param string $value
         *
-        * @throws InvalidArgumentException
+        * @throws IllegalValueException
         */
        public function __construct( $languageCode, $value ) {
                if ( !is_string( $languageCode ) ) {
-                       throw new InvalidArgumentException( 'Can only construct 
MonolingualTextValue with a string language code' );
+                       throw new IllegalValueException( 'Can only construct 
MonolingualTextValue with a string language code' );
                }
                elseif ( $languageCode === '' ) {
-                       throw new InvalidArgumentException( 'Can only construct 
MonolingualTextValue with a language code of non-zero length' );
+                       throw new IllegalValueException( 'Can only construct 
MonolingualTextValue with a language code of non-zero length' );
                }
 
                if ( !is_string( $value ) ) {
-                       throw new InvalidArgumentException( 'Can only construct 
MonolingualTextValue with a string value' );
+                       throw new IllegalValueException( 'Can only construct 
MonolingualTextValue with a string value' );
                }
 
                $this->value = $value;
diff --git a/DataValues/includes/values/MultilingualTextValue.php 
b/DataValues/includes/values/MultilingualTextValue.php
index 1b94748..e688eff 100644
--- a/DataValues/includes/values/MultilingualTextValue.php
+++ b/DataValues/includes/values/MultilingualTextValue.php
@@ -2,8 +2,6 @@
 
 namespace DataValues;
 
-use InvalidArgumentException;
-
 /**
  * Class representing a multilingual text value.
  *
@@ -46,18 +44,18 @@
         *
         * @param MonolingualTextValue[] $monolingualValues
         *
-        * @throws InvalidArgumentException
+        * @throws IllegalValueException
         */
        public function __construct( array $monolingualValues ) {
                foreach ( $monolingualValues as $monolingualValue ) {
                        if ( !( $monolingualValue instanceof 
MonolingualTextValue ) ) {
-                               throw new InvalidArgumentException( 'Can only 
construct MultilingualTextValue from MonolingualTextValue objects' );
+                               throw new IllegalValueException( 'Can only 
construct MultilingualTextValue from MonolingualTextValue objects' );
                        }
 
                        $langCode = $monolingualValue->getLanguageCode();
 
                        if ( array_key_exists( $langCode, $this->texts ) ) {
-                               throw new InvalidArgumentException( 'Can only 
add a single MonolingualTextValue per language to a MultilingualTextValue' );
+                               throw new IllegalValueException( 'Can only add 
a single MonolingualTextValue per language to a MultilingualTextValue' );
                        }
 
                        $this->texts[$langCode] = $monolingualValue;
diff --git a/DataValues/includes/values/NumberValue.php 
b/DataValues/includes/values/NumberValue.php
index 6354ca0..27d7361 100644
--- a/DataValues/includes/values/NumberValue.php
+++ b/DataValues/includes/values/NumberValue.php
@@ -2,8 +2,6 @@
 
 namespace DataValues;
 
-use InvalidArgumentException;
-
 /**
  * Class representing a simple numeric value.
  *
@@ -47,11 +45,11 @@
         *
         * @param int|float $value
         *
-        * @throws InvalidArgumentException
+        * @throws IllegalValueException
         */
        public function __construct( $value ) {
                if ( !is_int( $value ) && !is_float( $value ) ) {
-                       throw new InvalidArgumentException( 'Can only construct 
NumberValue from floats or integers' );
+                       throw new IllegalValueException( 'Can only construct 
NumberValue from floats or integers' );
                }
 
                $this->value = $value;
diff --git a/DataValues/includes/values/QuantityValue.php 
b/DataValues/includes/values/QuantityValue.php
index bf6188d..718d89d 100644
--- a/DataValues/includes/values/QuantityValue.php
+++ b/DataValues/includes/values/QuantityValue.php
@@ -2,8 +2,6 @@
 
 namespace DataValues;
 
-use InvalidArgumentException;
-
 /**
  * Class representing a numeric value with associated unit and accuracy.
  *
@@ -62,19 +60,19 @@
         * @param string|null $unit
         * @param int|float|null $accuracy
         *
-        * @throws InvalidArgumentException
+        * @throws IllegalValueException
         */
        public function __construct( $amount, $unit = null, $accuracy = null ) {
                if ( !is_int( $amount ) && !is_float( $amount ) ) {
-                       throw new InvalidArgumentException( 'Can only construct 
QuantityValue from floats or integers' );
+                       throw new IllegalValueException( 'Can only construct 
QuantityValue from floats or integers' );
                }
 
                if ( $accuracy !== null && !is_int( $accuracy ) && !is_float( 
$accuracy ) ) {
-                       throw new InvalidArgumentException( 'The accuracy of a 
QuantityValue needs to be a float or integer' );
+                       throw new IllegalValueException( 'The accuracy of a 
QuantityValue needs to be a float or integer' );
                }
 
                if ( $unit !== null && !is_string( $unit ) ) {
-                       throw new InvalidArgumentException( 'The unit of a 
QuantityValue needs to be a string' );
+                       throw new IllegalValueException( 'The unit of a 
QuantityValue needs to be a string' );
                }
 
                $this->value = $amount;
diff --git a/DataValues/includes/values/StringValue.php 
b/DataValues/includes/values/StringValue.php
index e7eac45..ce8ac84 100644
--- a/DataValues/includes/values/StringValue.php
+++ b/DataValues/includes/values/StringValue.php
@@ -2,8 +2,6 @@
 
 namespace DataValues;
 
-use InvalidArgumentException;
-
 /**
  * Class representing a string value.
  *
@@ -44,11 +42,11 @@
         *
         * @param string $value
         *
-        * @throws InvalidArgumentException
+        * @throws IllegalValueException
         */
        public function __construct( $value ) {
                if ( !is_string( $value ) ) {
-                       throw new InvalidArgumentException( 'Can only construct 
StringValue from strings' );
+                       throw new IllegalValueException( 'Can only construct 
StringValue from strings' );
                }
 
                $this->value = $value;
diff --git a/DataValues/includes/values/TimeValue.php 
b/DataValues/includes/values/TimeValue.php
index 6b58e60..8b71731 100644
--- a/DataValues/includes/values/TimeValue.php
+++ b/DataValues/includes/values/TimeValue.php
@@ -2,9 +2,6 @@
 
 namespace DataValues;
 
-use InvalidArgumentException;
-use OutOfBoundsException;
-
 /**
  * Class representing a time value.
  * @see https://meta.wikimedia.org/wiki/Wikidata/Data_model#Dates_and_times
@@ -117,40 +114,39 @@
         * @param integer $precision
         * @param string $calendarModel
         *
-        * @throws InvalidArgumentException
-        * @throws OutOfBoundsException
+        * @throws IllegalValueException
         */
        public function __construct( $time, $timezone, $before, $after, 
$precision, $calendarModel ) {
                if ( !is_string( $time ) ) {
-                       throw new InvalidArgumentException( '$time needs to be 
a string' );
+                       throw new IllegalValueException( '$time needs to be a 
string' );
                }
 
                if ( !is_integer( $timezone ) ) {
-                       throw new InvalidArgumentException( '$timezone needs to 
be an integer' );
+                       throw new IllegalValueException( '$timezone needs to be 
an integer' );
                }
 
                if ( $timezone < -12 * 3600 || $timezone > 14 * 3600 ) {
-                       throw new OutOfBoundsException( '$timezone out of 
allowed bounds' );
+                       throw new IllegalValueException( '$timezone out of 
allowed bounds' );
                }
 
                if ( !is_integer( $before ) || $before < 0 ) {
-                       throw new InvalidArgumentException( '$before needs to 
be an unsigned integer' );
+                       throw new IllegalValueException( '$before needs to be 
an unsigned integer' );
                }
 
                if ( !is_integer( $after ) || $after < 0 ) {
-                       throw new InvalidArgumentException( '$after needs to be 
an unsigned integer' );
+                       throw new IllegalValueException( '$after needs to be an 
unsigned integer' );
                }
 
                if ( !is_integer( $precision ) ) {
-                       throw new InvalidArgumentException( '$precision needs 
to be an integer' );
+                       throw new IllegalValueException( '$precision needs to 
be an integer' );
                }
 
                if ( $precision < self::PRECISION_Ga || $precision > 
self::PRECISION_SECOND ) {
-                       throw new OutOfBoundsException( '$precision out of 
allowed bounds' );
+                       throw new IllegalValueException( '$precision out of 
allowed bounds' );
                }
 
                if ( !is_string( $calendarModel ) ) {
-                       throw new InvalidArgumentException( '$calendarModel 
needs to be a string' );
+                       throw new IllegalValueException( '$calendarModel needs 
to be a string' );
                }
 
                // Can haz scalar type hints plox? ^^
@@ -282,7 +278,7 @@
         * @param string $value
         *
         * @return MonolingualTextValue
-        * @throws InvalidArgumentException
+        * @throws IllegalValueException
         */
        public function unserialize( $value ) {
                list( $time, $timezone, $before, $after, $precision, 
$calendarModel ) = json_decode( $value );
diff --git a/DataValues/includes/values/UnknownValue.php 
b/DataValues/includes/values/UnknownValue.php
index 8894518..c4c6ee5 100644
--- a/DataValues/includes/values/UnknownValue.php
+++ b/DataValues/includes/values/UnknownValue.php
@@ -2,8 +2,6 @@
 
 namespace DataValues;
 
-use InvalidArgumentException;
-
 /**
  * Class representing a value of unknown type.
  * This is in essence a null-wrapper, useful for instance for null-parsers.
@@ -44,8 +42,6 @@
         * @since 0.1
         *
         * @param mixed $value
-        *
-        * @throws InvalidArgumentException
         */
        public function __construct( $value ) {
                $this->value = $value;
diff --git a/DataValues/tests/phpunit/includes/values/TimeValueTest.php 
b/DataValues/tests/phpunit/includes/values/TimeValueTest.php
index 4ec1a77..c4e3a5e 100644
--- a/DataValues/tests/phpunit/includes/values/TimeValueTest.php
+++ b/DataValues/tests/phpunit/includes/values/TimeValueTest.php
@@ -87,7 +87,7 @@
                );
 
                $argLists[] = array(
-                       'InvalidArgumentException',
+                       'DataValues\IllegalValueException',
                        '+00000002013-01-01T00:00:00Z',
                        '0',
                        0,
@@ -97,7 +97,7 @@
                );
 
                $argLists[] = array(
-                       'InvalidArgumentException',
+                       'DataValues\IllegalValueException',
                        '+00000002013-01-01T00:00:00Z',
                        4.2,
                        0,
@@ -107,7 +107,7 @@
                );
 
                $argLists[] = array(
-                       'OutOfBoundsException',
+                       'DataValues\IllegalValueException',
                        '+00000002013-01-01T00:00:00Z',
                        -20 * 3600,
                        0,
@@ -117,7 +117,7 @@
                );
 
                $argLists[] = array(
-                       'OutOfBoundsException',
+                       'DataValues\IllegalValueException',
                        '+00000002013-01-01T00:00:00Z',
                        0,
                        0,
@@ -127,7 +127,7 @@
                );
 
                $argLists[] = array(
-                       'OutOfBoundsException',
+                       'DataValues\IllegalValueException',
                        '+00000002013-01-01T00:00:00Z',
                        0,
                        0,
@@ -137,7 +137,7 @@
                );
 
                $argLists[] = array(
-                       'InvalidArgumentException',
+                       'DataValues\IllegalValueException',
                        42,
                        0,
                        0,
@@ -147,7 +147,7 @@
                );
 
                $argLists[] = array(
-                       'InvalidArgumentException',
+                       'DataValues\IllegalValueException',
                        '+00000002013-01-01T00:00:00Z',
                        0,
                        4.2,
@@ -157,7 +157,7 @@
                );
 
                $argLists[] = array(
-                       'InvalidArgumentException',
+                       'DataValues\IllegalValueException',
                        '+00000002013-01-01T00:00:00Z',
                        0,
                        0,

-- 
To view, visit https://gerrit.wikimedia.org/r/67812
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ib7d85555748630a367b1f79a17ab02490d00ba26
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/DataValues
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Daniel Werner <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to