jenkins-bot has submitted this change and it was merged.
Change subject: Add type hints to ExceptionLocalizer classes
......................................................................
Add type hints to ExceptionLocalizer classes
Patch set 1 introduced code duplication, instead I'm adding @var
comments now to avoid code analysis tools complaining about calling
non-existing methods.
This also inlines some trivial and unused code, e.g. the empty
array() was unused.
Change-Id: If0e218296773ca05083db9906a04bf888255cdbf
---
M lib/includes/Localizer/MessageExceptionLocalizer.php
M lib/includes/Localizer/ParseExceptionLocalizer.php
M repo/includes/Localizer/ChangeOpValidationExceptionLocalizer.php
3 files changed, 15 insertions(+), 15 deletions(-)
Approvals:
Daniel Kinzler: Looks good to me, approved
jenkins-bot: Verified
diff --git a/lib/includes/Localizer/MessageExceptionLocalizer.php
b/lib/includes/Localizer/MessageExceptionLocalizer.php
index be98467..d1a0057 100644
--- a/lib/includes/Localizer/MessageExceptionLocalizer.php
+++ b/lib/includes/Localizer/MessageExceptionLocalizer.php
@@ -27,6 +27,7 @@
throw new InvalidArgumentException( '$exception is not
a MessageException.' );
}
+ /** @var MessageException $exception */
$key = $exception->getKey();
$params = $exception->getParams();
$msg = wfMessage( $key )->params( $params );
@@ -44,4 +45,5 @@
public function hasExceptionMessage( Exception $exception ) {
return $exception instanceof MessageException;
}
+
}
diff --git a/lib/includes/Localizer/ParseExceptionLocalizer.php
b/lib/includes/Localizer/ParseExceptionLocalizer.php
index dc2dc99..d1f14fd 100644
--- a/lib/includes/Localizer/ParseExceptionLocalizer.php
+++ b/lib/includes/Localizer/ParseExceptionLocalizer.php
@@ -29,26 +29,21 @@
throw new InvalidArgumentException( '$exception is not
a ParseException' );
}
- $baseKey = 'wikibase-parse-error';
- $params = array();
$msg = null;
- // Messages that can be used here:
- // * wikibase-parse-error
- // * wikibase-parse-error-coordinate
- // * wikibase-parse-error-entity-id
- // * wikibase-parse-error-quantity
- // * wikibase-parse-error-time
+ /** @var ParseException $exception */
$expectedFormat = $exception->getExpectedFormat();
- if( $expectedFormat !== null ) {
- $msg = new Message( $baseKey . '-' . $expectedFormat,
$params );
- if( !$msg->exists() ) {
- $msg = null;
- }
+ if ( $expectedFormat !== null ) {
+ // Messages:
+ // wikibase-parse-error-coordinate
+ // wikibase-parse-error-entity-id
+ // wikibase-parse-error-quantity
+ // wikibase-parse-error-time
+ $msg = new Message( 'wikibase-parse-error-' .
$expectedFormat );
}
- if( $msg === null ) {
- $msg = new Message( $baseKey, $params );
+ if ( !( $msg instanceof Message ) || !$msg->exists() ) {
+ $msg = new Message( 'wikibase-parse-error' );
}
return $msg;
@@ -64,4 +59,5 @@
public function hasExceptionMessage( Exception $exception ) {
return $exception instanceof ParseException;
}
+
}
diff --git a/repo/includes/Localizer/ChangeOpValidationExceptionLocalizer.php
b/repo/includes/Localizer/ChangeOpValidationExceptionLocalizer.php
index c2198a4..172006f 100644
--- a/repo/includes/Localizer/ChangeOpValidationExceptionLocalizer.php
+++ b/repo/includes/Localizer/ChangeOpValidationExceptionLocalizer.php
@@ -37,12 +37,14 @@
*
* @throws InvalidArgumentException
* @return Message
+ * @throws InvalidArgumentException
*/
public function getExceptionMessage( Exception $exception ) {
if ( !$this->hasExceptionMessage( $exception ) ) {
throw new InvalidArgumentException( '$exception is not
a ChangeOpValidationException.' );
}
+ /** @var ChangeOpValidationException $exception */
$result = $exception->getValidationResult();
foreach ( $result->getErrors() as $error ) {
--
To view, visit https://gerrit.wikimedia.org/r/188359
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: If0e218296773ca05083db9906a04bf888255cdbf
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: Adrian Lang <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits