Tpt has uploaded a new change for review.
https://gerrit.wikimedia.org/r/90145
Change subject: Removes MWException from serializer objects
......................................................................
Removes MWException from serializer objects
Change-Id: Ie1d2b2ed31d08e02ef5e7b461759851f43ac7cb9
---
M lib/includes/serializers/ByPropertyListSerializer.php
M lib/includes/serializers/ByPropertyListUnserializer.php
M lib/includes/serializers/ClaimSerializer.php
M lib/includes/serializers/ClaimsSerializer.php
M lib/includes/serializers/EntitySerializer.php
M lib/includes/serializers/ItemSerializer.php
M lib/includes/serializers/PropertySerializer.php
M lib/includes/serializers/ReferenceSerializer.php
M lib/includes/serializers/SerializationOptions.php
M lib/includes/serializers/Serializer.php
M lib/includes/serializers/SerializerObject.php
M lib/includes/serializers/SnakSerializer.php
M lib/includes/serializers/Unserializer.php
M repo/includes/api/SetClaim.php
M repo/includes/api/SetReference.php
15 files changed, 74 insertions(+), 59 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/45/90145/1
diff --git a/lib/includes/serializers/ByPropertyListSerializer.php
b/lib/includes/serializers/ByPropertyListSerializer.php
index 5096efb..b487c31 100644
--- a/lib/includes/serializers/ByPropertyListSerializer.php
+++ b/lib/includes/serializers/ByPropertyListSerializer.php
@@ -1,7 +1,9 @@
<?php
namespace Wikibase\Lib\Serializers;
-use Traversable, ApiResult, MWException;
+
+use Traversable;
+use InvalidArgumentException;
use Wikibase\DataModel\Entity\PropertyId;
/**
@@ -73,11 +75,11 @@
* @param mixed $objects
*
* @return array
- * @throws MWException
+ * @throws InvalidArgumentException
*/
public function getSerialized( $objects ) {
if ( !( $objects instanceof Traversable ) ) {
- throw new MWException( 'ByPropertyListSerializer can
only serialize Traversable objects' );
+ throw new InvalidArgumentException(
'ByPropertyListSerializer can only serialize Traversable objects' );
}
$serialization = array();
diff --git a/lib/includes/serializers/ByPropertyListUnserializer.php
b/lib/includes/serializers/ByPropertyListUnserializer.php
index 3f2ac41..ca99b9e 100644
--- a/lib/includes/serializers/ByPropertyListUnserializer.php
+++ b/lib/includes/serializers/ByPropertyListUnserializer.php
@@ -1,7 +1,9 @@
<?php
namespace Wikibase\Lib\Serializers;
-use ApiResult, MWException;
+
+use InvalidArgumentException;
+use OutOfBoundsException;
/**
* Serializer for Traversable objects that need to be grouped
@@ -58,14 +60,15 @@
* @param array $serialization
*
* @return array
- * @throws MWException
+ * @throws InvalidArgumentException
+ * @throws OutOfBoundsException
*/
public function newFromSerialization( array $serialization ) {
$elements = array();
foreach ( $serialization as $propertyId => $byPropId ) {
if ( !is_array( $byPropId ) ) {
- throw new MWException( "Element with key
'$propertyId' should be an array, found " . gettype( $byPropId ) );
+ throw new InvalidArgumentException( "Element
with key '$propertyId' should be an array, found " . gettype( $byPropId ) );
}
foreach ( $byPropId as $serializedElement ) {
@@ -74,7 +77,7 @@
$elementPropertyId =
$element->getPropertyId()->getPrefixedId();
if ( $elementPropertyId !== $propertyId ) {
- throw new MWException( "Element with id
'$elementPropertyId' found in list with id '$propertyId'" );
+ throw new OutOfBoundsException(
"Element with id '$elementPropertyId' found in list with id '$propertyId'" );
}
$elements[] = $element;
diff --git a/lib/includes/serializers/ClaimSerializer.php
b/lib/includes/serializers/ClaimSerializer.php
index ec81dcd..36bd2ca 100644
--- a/lib/includes/serializers/ClaimSerializer.php
+++ b/lib/includes/serializers/ClaimSerializer.php
@@ -1,7 +1,9 @@
<?php
namespace Wikibase\Lib\Serializers;
-use MWException;
+
+use InvalidArgumentException;
+use OutOfBoundsException;
use Wikibase\Statement;
use Wikibase\Claim;
@@ -92,11 +94,11 @@
* @param mixed $claim
*
* @return array
- * @throws MWException
+ * @throws InvalidArgumentException
*/
public function getSerialized( $claim ) {
if ( !( $claim instanceof Claim ) ) {
- throw new MWException( 'ClaimSerializer can only
serialize Claim objects' );
+ throw new InvalidArgumentException( 'ClaimSerializer
can only serialize Claim objects' );
}
$serialization['id'] = $claim->getGuid();
@@ -152,12 +154,13 @@
* @param array $serialization
*
* @return Claim
- * @throws MWException
+ * @throws InvalidArgumentException
+ * @throws OutOfBoundsException
*/
public function newFromSerialization( array $serialization ) {
if ( !array_key_exists( 'type', $serialization )
|| !in_array( $serialization['type'], array( 'claim',
'statement' ) ) ) {
- throw new MWException( 'Invalid claim type specified' );
+ throw new InvalidArgumentException( 'Invalid claim type
specified' );
}
$requiredElements = array(
@@ -172,7 +175,7 @@
foreach ( $requiredElements as $requiredElement ) {
if ( !array_key_exists( $requiredElement,
$serialization ) ) {
- throw new MWException( "Required key
'$requiredElement' missing" );
+ throw new InvalidArgumentException( "Required
key '$requiredElement' missing" );
}
}
@@ -194,7 +197,7 @@
if ( $isStatement ) {
if ( !in_array( $serialization['rank'], self::$rankMap
) ) {
- throw new MWException( 'Invalid statement rank
provided' );
+ throw new InvalidArgumentException( 'Invalid
statement rank provided' );
}
/**
@@ -226,7 +229,7 @@
* @param array $serialization
* @param SnakSerializer $snakUnserializer
* @return \Wikibase\SnakList
- * @throws \MWException
+ * @throws OutOfBoundsException
*/
protected function unserializeQualifiers( $serialization,
$snakUnserializer ) {
if ( !array_key_exists( 'qualifiers', $serialization ) ) {
@@ -240,7 +243,7 @@
} else {
foreach( $serialization['qualifiers-order'] as
$propertyId ) {
if( !isset(
$serialization['qualifiers'][$propertyId] ) ) {
- throw new MWException( 'No
snaks with property id "' . $propertyId . '" '
+ throw new OutOfBoundsException(
'No snaks with property id "' . $propertyId . '" '
. 'found in "qualifiers"
parameter although specified in '
. '"qualifiers-order"' );
}
@@ -254,7 +257,7 @@
);
if( count( $missingProperties ) > 0 ) {
- throw new MWException( 'Property ids '
. implode( ', ', $missingProperties )
+ throw new OutOfBoundsException(
'Property ids ' . implode( ', ', $missingProperties )
. ' have not been specified in
"qualifiers-order"' );
}
}
diff --git a/lib/includes/serializers/ClaimsSerializer.php
b/lib/includes/serializers/ClaimsSerializer.php
index 1d56331..37d2950 100644
--- a/lib/includes/serializers/ClaimsSerializer.php
+++ b/lib/includes/serializers/ClaimsSerializer.php
@@ -1,7 +1,9 @@
<?php
namespace Wikibase\Lib\Serializers;
-use MWException;
+
+use InvalidArgumentException;
+use OutOfBoundsException;
use Wikibase\Claims;
/**
@@ -40,11 +42,11 @@
* @param mixed $claims
*
* @return array
- * @throws MWException
+ * @throws InvalidArgumentException
*/
public function getSerialized( $claims ) {
if ( !( $claims instanceof \Wikibase\Claims ) ) {
- throw new MWException( 'ClaimsSerializer can only
serialize Claims objects' );
+ throw new InvalidArgumentException( 'ClaimsSerializer
can only serialize Claims objects' );
}
$claimSerializer = new ClaimSerializer( $this->options );
@@ -61,7 +63,8 @@
* @param mixed $serialization
*
* @return Claims
- * @throws MWException
+ * @throws InvalidArgumentException
+ * @throws OutOfBoundsException
*/
public function newFromSerialization( array $serialization ) {
$claimSerializer = new ClaimSerializer( $this->options );
diff --git a/lib/includes/serializers/EntitySerializer.php
b/lib/includes/serializers/EntitySerializer.php
index 1acb0b6..1d1186e 100644
--- a/lib/includes/serializers/EntitySerializer.php
+++ b/lib/includes/serializers/EntitySerializer.php
@@ -2,8 +2,7 @@
namespace Wikibase\Lib\Serializers;
-use ApiResult;
-use MWException;
+use InvalidArgumentException;
use Wikibase\Entity;
/**
@@ -46,11 +45,11 @@
* @param mixed $entity
*
* @return array
- * @throws MWException
+ * @throws InvalidArgumentException
*/
final public function getSerialized( $entity ) {
if ( !( $entity instanceof Entity ) ) {
- throw new MWException( 'EntitySerializer can only
serialize Entity objects' );
+ throw new InvalidArgumentException( 'EntitySerializer
can only serialize Entity objects' );
}
$serialization['id'] = $entity->getId() ?
$entity->getId()->getPrefixedId() : '';
diff --git a/lib/includes/serializers/ItemSerializer.php
b/lib/includes/serializers/ItemSerializer.php
index e326357..e284d1d 100644
--- a/lib/includes/serializers/ItemSerializer.php
+++ b/lib/includes/serializers/ItemSerializer.php
@@ -1,7 +1,8 @@
<?php
namespace Wikibase\Lib\Serializers;
-use MWException;
+
+use InvalidArgumentException;
use Wikibase\Entity;
use Wikibase\Item;
@@ -66,11 +67,11 @@
* @param Entity $item
*
* @return array
- * @throws MWException
+ * @throws InvalidArgumentException
*/
protected function getEntityTypeSpecificSerialization( Entity $item ) {
if ( !( $item instanceof Item ) ) {
- throw new MWException( 'ItemSerializer can only
serialize Item implementing objects' );
+ throw new InvalidArgumentException( 'ItemSerializer can
only serialize Item implementing objects' );
}
$serialization = array();
diff --git a/lib/includes/serializers/PropertySerializer.php
b/lib/includes/serializers/PropertySerializer.php
index 5d9b3f2..0eacd55 100644
--- a/lib/includes/serializers/PropertySerializer.php
+++ b/lib/includes/serializers/PropertySerializer.php
@@ -2,7 +2,7 @@
namespace Wikibase\Lib\Serializers;
-use MWException;
+use InvalidArgumentException;
use Wikibase\Entity;
use Wikibase\Property;
@@ -42,11 +42,11 @@
* @param Entity $property
*
* @return array
- * @throws MWException
+ * @throws InvalidArgumentException
*/
protected function getEntityTypeSpecificSerialization( Entity $property
) {
if ( !( $property instanceof Property ) ) {
- throw new MWException( 'PropertySerializer can only
serialize Property implementing objects' );
+ throw new InvalidArgumentException( 'PropertySerializer
can only serialize Property implementing objects' );
}
$serialization = array();
diff --git a/lib/includes/serializers/ReferenceSerializer.php
b/lib/includes/serializers/ReferenceSerializer.php
index af3669d..7b95723 100644
--- a/lib/includes/serializers/ReferenceSerializer.php
+++ b/lib/includes/serializers/ReferenceSerializer.php
@@ -1,7 +1,9 @@
<?php
namespace Wikibase\Lib\Serializers;
-use MWException;
+
+use InvalidArgumentException;
+use OutOfBoundsException;
use Wikibase\Reference;
/**
@@ -40,11 +42,11 @@
* @param mixed $reference
*
* @return array
- * @throws MWException
+ * @throws InvalidArgumentException
*/
public function getSerialized( $reference ) {
if ( !( $reference instanceof Reference ) ) {
- throw new MWException( 'ReferenceSerializer can only
serialize Reference objects' );
+ throw new InvalidArgumentException(
'ReferenceSerializer can only serialize Reference objects' );
}
$serialization = array();
@@ -76,11 +78,12 @@
* @param array $serialization
*
* @return Reference
- * @throws MWException
+ * @throws InvalidArgumentException
+ * @throws OutOfBoundsException
*/
public function newFromSerialization( array $serialization ) {
if ( !array_key_exists( 'snaks', $serialization ) || !is_array(
$serialization['snaks'] ) ) {
- throw new MWException( 'A reference serialization needs
to have a list of snaks' );
+ throw new InvalidArgumentException( 'A reference
serialization needs to have a list of snaks' );
}
$sortedSnaks = array();
@@ -94,7 +97,7 @@
} else {
foreach( $serialization['snaks-order'] as $propertyId )
{
if( !isset(
$serialization['snaks'][$propertyId] ) ) {
- throw new MWException( 'No snaks with
property id "' . $propertyId . '" found '
+ throw new OutOfBoundsException( 'No
snaks with property id "' . $propertyId . '" found '
. 'in "snaks" parameter although
specified in "snaks-order"' );
}
@@ -104,7 +107,7 @@
$missingProperties = array_diff_key( $sortedSnaks,
$serialization['snaks'] );
if( count( $missingProperties ) > 0 ) {
- throw new MWException( 'Property ids ' .
implode( ', ', $missingProperties )
+ throw new OutOfBoundsException( 'Property ids '
. implode( ', ', $missingProperties )
. ' have not been specified in "snaks-order"' );
}
}
@@ -117,7 +120,7 @@
$reference = new Reference( new \Wikibase\SnakList( $snaks ) );
if ( array_key_exists( 'hash', $serialization ) &&
$serialization['hash'] !== $reference->getHash() ) {
- throw new MWException( 'If a hash is present in a
reference serialization it needs to be correct' );
+ throw new InvalidArgumentException( 'If a hash is
present in a reference serialization it needs to be correct' );
}
return $reference;
diff --git a/lib/includes/serializers/SerializationOptions.php
b/lib/includes/serializers/SerializationOptions.php
index d9fa81f..a17a7fa 100644
--- a/lib/includes/serializers/SerializationOptions.php
+++ b/lib/includes/serializers/SerializationOptions.php
@@ -2,7 +2,7 @@
namespace Wikibase\Lib\Serializers;
-use MWException;
+use InvalidArgumentException;
use ValueFormatters\ValueFormatter;
use Wikibase\LanguageFallbackChainFactory;
@@ -42,11 +42,11 @@
*
* @param boolean $indexTags
*
- * @throws MWException
+ * @throws InvalidArgumentException
*/
public function setIndexTags( $indexTags ) {
if ( !is_bool( $indexTags ) ) {
- throw new MWException( 'Expected boolean, got something
else' );
+ throw new InvalidArgumentException( 'Expected boolean,
got something else' );
}
$this->indexTags = $indexTags;
@@ -390,11 +390,11 @@
* @since 0.2
*
* @param string $sortDirection Element of the
EntitySerializationOptions::SORT_ enum
- * @throws MWException
+ * @throws InvalidArgumentException
*/
public function setSortDirection( $sortDirection ) {
if ( !in_array( $sortDirection, array( self::SORT_ASC,
self::SORT_DESC, self::SORT_NONE ) ) ) {
- throw new MWException( 'Invalid sort direction
provided' );
+ throw new InvalidArgumentException( 'Invalid sort
direction provided' );
}
$this->sortDirection = $sortDirection;
diff --git a/lib/includes/serializers/Serializer.php
b/lib/includes/serializers/Serializer.php
index da69de7..3a4d091 100644
--- a/lib/includes/serializers/Serializer.php
+++ b/lib/includes/serializers/Serializer.php
@@ -1,7 +1,6 @@
<?php
namespace Wikibase\Lib\Serializers;
-use MWException;
/**
* Interface for objects that can transform variables of a certain type into
an array
diff --git a/lib/includes/serializers/SerializerObject.php
b/lib/includes/serializers/SerializerObject.php
index a607835..6913485 100644
--- a/lib/includes/serializers/SerializerObject.php
+++ b/lib/includes/serializers/SerializerObject.php
@@ -1,7 +1,6 @@
<?php
namespace Wikibase\Lib\Serializers;
-use ApiResult, MWException;
/**
* Base class for ApiSerializers.
@@ -47,7 +46,6 @@
*
* @since 0.3
*
- * @param ApiResult $apiResult
* @param SerializationOptions|null $options
*/
public function __construct( SerializationOptions $options = null ) {
diff --git a/lib/includes/serializers/SnakSerializer.php
b/lib/includes/serializers/SnakSerializer.php
index bd86221..0769ac1 100644
--- a/lib/includes/serializers/SnakSerializer.php
+++ b/lib/includes/serializers/SnakSerializer.php
@@ -1,7 +1,8 @@
<?php
namespace Wikibase\Lib\Serializers;
-use MWException;
+
+use InvalidArgumentException;
use Wikibase\Snak;
use Wikibase\SnakObject;
@@ -41,11 +42,11 @@
* @param mixed $snak
*
* @return array
- * @throws MWException
+ * @throws InvalidArgumentException
*/
public function getSerialized( $snak ) {
if ( !( $snak instanceof Snak ) ) {
- throw new MWException( 'SnakSerializer can only
serialize Snak objects' );
+ throw new InvalidArgumentException( 'SnakSerializer can
only serialize Snak objects' );
}
$serialization = array();
diff --git a/lib/includes/serializers/Unserializer.php
b/lib/includes/serializers/Unserializer.php
index 725dd30..ee26d40 100644
--- a/lib/includes/serializers/Unserializer.php
+++ b/lib/includes/serializers/Unserializer.php
@@ -1,7 +1,6 @@
<?php
namespace Wikibase\Lib\Serializers;
-use MWException;
/**
* Interface for service objects doing unserialization.
diff --git a/repo/includes/api/SetClaim.php b/repo/includes/api/SetClaim.php
index 37118a3..c40c130 100644
--- a/repo/includes/api/SetClaim.php
+++ b/repo/includes/api/SetClaim.php
@@ -5,7 +5,8 @@
use ApiMain;
use ApiBase;
use MWException;
-use DataValues\IllegalValueException;
+use InvalidArgumentException;
+use OutOfBoundsException;
use Diff\Comparer\ComparableComparer;
use Diff\OrderedListDiffer;
use FormatJson;
@@ -112,10 +113,10 @@
throw new IllegalValueException( 'Failed to get
claim from claim Serialization' );
}
return $claim;
- } catch ( IllegalValueException $illegalValueException ) {
- $this->dieUsage( $illegalValueException->getMessage(),
'invalid-claim' );
- } catch( MWException $mwException ) {
- $this->dieUsage( 'Failed to get claim from claim
Serialization ' . $mwException->getMessage(), 'invalid-claim' );
+ } catch( InvalidArgumentException $invalidArgumentException ) {
+ $this->dieUsage( 'Failed to get claim from claim
Serialization ' . $invalidArgumentException->getMessage(), 'invalid-claim' );
+ } catch( OutOfBoundsException $outOfBoundsException ) {
+ $this->dieUsage( 'Failed to get claim from claim
Serialization ' . $outOfBoundsException->getMessage(), 'invalid-claim' );
}
}
diff --git a/repo/includes/api/SetReference.php
b/repo/includes/api/SetReference.php
index 7e0f77c..a029baf 100644
--- a/repo/includes/api/SetReference.php
+++ b/repo/includes/api/SetReference.php
@@ -3,6 +3,8 @@
namespace Wikibase\Api;
use ApiBase;
+use InvalidArgumentException;
+use OutOfBoundsException;
use Wikibase\Repo\WikibaseRepo;
use Wikibase\ChangeOp\ChangeOpReference;
use Wikibase\ChangeOp\ChangeOpException;
@@ -10,7 +12,6 @@
use Wikibase\Statement;
use Wikibase\Reference;
use Wikibase\Lib\Serializers\SerializerFactory;
-use DataValues\IllegalValueException;
/**
* API module for creating a reference or setting the value of an existing one.
@@ -170,9 +171,11 @@
$snaks[] = $snak;
}
}
- } catch ( IllegalValueException $ex ) {
+ } catch( InvalidArgumentException $invalidArgumentException ) {
// Handle Snak instantiation failures
- $this->dieUsage( 'Invalid snak JSON given.
IllegalValueException', 'invalid-json' );
+ $this->dieUsage( 'Failed to get reference from
reference Serialization ' . $invalidArgumentException->getMessage() );
+ } catch( OutOfBoundsException $outOfBoundsException ) {
+ $this->dieUsage( 'Failed to get reference from
reference Serialization ' . $outOfBoundsException->getMessage() );
}
return $snaks;
--
To view, visit https://gerrit.wikimedia.org/r/90145
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie1d2b2ed31d08e02ef5e7b461759851f43ac7cb9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Tpt <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits