From 924a00da15047f4cab65eb2fa5a1c5c3f4f31d36 Mon Sep 17 00:00:00 2001 From: Ollie Shotton Date: Tue, 16 Aug 2022 22:54:37 +0100 Subject: [PATCH] DM: Add type hints to Statement * Investigation into adding type hints to the Wikibase DataModel by first type hinting a part of the DataModel. * Remove support for calling `Statement::addNewReference()` with a single array argument, which was deprecated in `Version 9.6.0 (2021-03-31)`. This should now be called with a variadic argument list. Bug: T314769 Change-Id: I179ffb3c421b5c01d59a2bd9d166f679e0441619 --- .../LegacyStatementDeserializer.php | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/Deserializers/LegacyStatementDeserializer.php b/src/Deserializers/LegacyStatementDeserializer.php index 88505de..860f98f 100644 --- a/src/Deserializers/LegacyStatementDeserializer.php +++ b/src/Deserializers/LegacyStatementDeserializer.php @@ -1,4 +1,4 @@ -snakDeserializer->deserialize( $serialization['m'] ), - $this->snakListDeserializer->deserialize( $serialization['q'] ), - $this->getReferences( $serialization['refs'] ) - ); + /* @var Snak $snak */ + $snak = $this->snakDeserializer->deserialize( $serialization['m'] ); + /* @var SnakList $snakList */ + $snakList = $this->snakListDeserializer->deserialize( $serialization['q'] ); + $statement = new Statement( $snak, $snakList, $this->getReferences( $serialization['refs'] ) ); try { $statement->setRank( $serialization['rank'] ); $statement->setGuid( $serialization['g'] ); - } catch ( InvalidArgumentException $ex ) { - throw new DeserializationException( $ex->getMessage(), $ex ); + } catch ( TypeError $ex ) { + // DeserializationException only accepts Exception instead of Throwable, like it's parent + // TODO: uncomment $ex when DeserializationException accepts Throwable + throw new DeserializationException( $ex->getMessage() /*, $ex*/ ); } return $statement; @@ -98,8 +100,8 @@ private function getReferences( array $refs ) { */ public function isDeserializerFor( $serialization ) { return is_array( $serialization ) - // This element is called 'mainsnak' in the current serialization. - && array_key_exists( 'm', $serialization ); + // This element is called 'mainsnak' in the current serialization. + && array_key_exists( 'm', $serialization ); } }