jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/341345 )

Change subject: Fixups to Language- and LexicalCategoryChangeOpDeserializers
......................................................................


Fixups to Language- and LexicalCategoryChangeOpDeserializers

This fixes a few minor issues:

* I'm not sure if the StringNormalizer actually accepts null. The
documentation requires a string. It should not be called with null.

* One of the isset() checks was done *after* a possibly not existing
array key was accessed.

Change-Id: I430a0cb447f77a6b0985e5ae849779007ea4922e
---
M docs/change-op-serialization.wiki
M src/ChangeOp/Deserialization/LanguageChangeOpDeserializer.php
M src/ChangeOp/Deserialization/LexicalCategoryChangeOpDeserializer.php
3 files changed, 20 insertions(+), 20 deletions(-)

Approvals:
  WMDE-leszek: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/docs/change-op-serialization.wiki 
b/docs/change-op-serialization.wiki
index 5270ec3..e8e56f1 100644
--- a/docs/change-op-serialization.wiki
+++ b/docs/change-op-serialization.wiki
@@ -6,7 +6,8 @@
 
 === Language ===
 
-* A language is defined by adding a "language" key to the change request JSON 
array. The value should be a string containing the ID of an existing item. In 
order to remove it, you can set it to empty string or null. That item should be 
a about a language (for example French or Chinese), but we don't enforce that, 
and constraint reports should take care of such violations.
+* A language is defined by adding a "language" key to the change request JSON 
array. The value should be a string containing the ID of an existing item. That 
item should be a about a language (for example French or Chinese), but we don't 
enforce that, and constraint reports should take care of such violations.
+* In order to remove the language, you can set it to an empty string or null.
 
 Example of a change request setting language to "Q666" can be seen below (only 
relevant parts of the request included in the example).
 
@@ -41,7 +42,8 @@
 </syntaxhighlight>
 
 === Lexical category ===
-* The lexical category is defined by adding a "lexicalCategory" key to the 
change request JSON array. The value should be a string containing the ID of an 
existing item. In order to remove it, you can set it to empty string or null. 
That item should be a about a lexical category (for example verb or noun), but 
we don't enforce that, and constraint reports should take care of such 
violations.
+* The lexical category is defined by adding a "lexicalCategory" key to the 
change request JSON array. The value should be a string containing the ID of an 
existing item. That item should be about a lexical category (for example verb 
or noun), but we don't enforce that, and constraint reports should take care of 
such violations.
+* In order to remove the lexical category, you can set it to empty string or 
null.
 
 Example of a change request setting lexical category to "Q42" can be seen 
below (only relevant parts of the request included in the example).
 
diff --git a/src/ChangeOp/Deserialization/LanguageChangeOpDeserializer.php 
b/src/ChangeOp/Deserialization/LanguageChangeOpDeserializer.php
index 06af14c..0730d2f 100644
--- a/src/ChangeOp/Deserialization/LanguageChangeOpDeserializer.php
+++ b/src/ChangeOp/Deserialization/LanguageChangeOpDeserializer.php
@@ -47,7 +47,7 @@
         * @return ChangeOp
         */
        public function createEntityChangeOp( array $changeRequest ) {
-               if ( !isset( $changeRequest['language'] )
+               if ( !array_key_exists( 'language', $changeRequest )
                        || ( !is_string( $changeRequest['language'] ) && 
$changeRequest['language'] !== null )
                ) {
                        throw new ChangeOpDeserializationException(
@@ -56,13 +56,14 @@
                        );
                }
 
-               $languageSerialization = $this->stringNormalizer->cleanupToNFC( 
$changeRequest['language'] );
+               $value = $changeRequest['language'];
+               $value = $value === null ? '' : 
$this->stringNormalizer->cleanupToNFC( $value );
 
-               if ( $languageSerialization === '' ) {
+               if ( $value === '' ) {
                        return new ChangeOpLanguage( null, 
$this->lexemeValidatorFactory );
                }
 
-               $itemId = $this->validateItemId( $languageSerialization );
+               $itemId = $this->validateItemId( $value );
                // TODO: maybe move creating ChangeOpLanguage instance to some 
kind of factory?
                return new ChangeOpLanguage( $itemId, 
$this->lexemeValidatorFactory );
        }
diff --git 
a/src/ChangeOp/Deserialization/LexicalCategoryChangeOpDeserializer.php 
b/src/ChangeOp/Deserialization/LexicalCategoryChangeOpDeserializer.php
index 3cddb22..8b91255 100644
--- a/src/ChangeOp/Deserialization/LexicalCategoryChangeOpDeserializer.php
+++ b/src/ChangeOp/Deserialization/LexicalCategoryChangeOpDeserializer.php
@@ -44,37 +44,34 @@
         * @param array $changeRequest
         *
         * @throws ChangeOpDeserializationException
-        *
         * @return ChangeOp
         */
        public function createEntityChangeOp( array $changeRequest ) {
-
-               $lexicalCategorySerialization = 
$changeRequest['lexicalCategory'];
-               if ( !isset( $lexicalCategorySerialization )
-                       || ( !is_string( $lexicalCategorySerialization ) && 
$lexicalCategorySerialization !== null )
+               if ( !array_key_exists( 'lexicalCategory', $changeRequest )
+                       || ( !is_string( $changeRequest['lexicalCategory'] )
+                               && $changeRequest['lexicalCategory'] !== null
+                       )
                ) {
                        throw new ChangeOpDeserializationException(
-                               'lexicalCategory must be string or null',
+                               'lexicalCategory must be a string or null',
                                'invalid-lexical-category'
                        );
                }
 
-               $lexicalCategorySerialization = 
$this->stringNormalizer->cleanupToNFC(
-                       $changeRequest['lexicalCategory'] );
+               $value = $changeRequest['lexicalCategory'];
+               $value = $value === null ? '' : 
$this->stringNormalizer->cleanupToNFC( $value );
 
-               if ( $lexicalCategorySerialization === '' ) {
-                       return new ChangeOpLexicalCategory(
-                               null,
-                               $this->lexemeValidatorFactory
-                       );
+               if ( $value === '' ) {
+                       return new ChangeOpLexicalCategory( null, 
$this->lexemeValidatorFactory );
                }
 
-               $itemId = $this->validateItemId( $lexicalCategorySerialization 
);
+               $itemId = $this->validateItemId( $value );
                return new ChangeOpLexicalCategory( $itemId, 
$this->lexemeValidatorFactory );
        }
 
        /**
         * @param string $idSerialization
+        *
         * @return ItemId
         * @throws ChangeOpDeserializationException
         */

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I430a0cb447f77a6b0985e5ae849779007ea4922e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseLexeme
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: Jakob <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: WMDE-leszek <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to