Skip to content

Fix incomplete (Unbounded)QuantityValue::newFromArray deserializers#85

Merged
brightbyte merged 1 commit into
masterfrom
quantityBuilder
Aug 3, 2016
Merged

Fix incomplete (Unbounded)QuantityValue::newFromArray deserializers#85
brightbyte merged 1 commit into
masterfrom
quantityBuilder

Conversation

@thiemowmde
Copy link
Copy Markdown
Contributor

I consider this a "fix" for the following reason:

  • The parser returns either an unbounded or a bounded quantity value.
  • The formatter accepts both.
  • Both do have a getArrayValue method, which is what defines the serialization. The serializers don't know anything about the two classes.
  • We are considering the fact that we split the code into two classes an implementation detail.
  • Deserialization is done in DataValueDeserializer, which calls newFromArray. This should still be possible without requiring an "IF upper and lower bound are present THEN deserialize bounded quantity value ELSE deserialize unbounded quantity value". This knowledge should be inside of this component (because it is an implementation detail). Not in Wikibase.git.
@thiemowmde thiemowmde added this to the 0.8.1 milestone Aug 2, 2016
Comment thread src/DataValues/QuantityValue.php Outdated
public static function newFromArray( array $data ) {
if ( !isset( $data['upperBound'] ) && !isset( $data['lowerBound'] ) ) {
return parent::newFromArray( $data );
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite unexpected, please add a warning or at least an explanation to the documentation.

Perhaps we should consider having a separate function for this - or even a QuantityValueFactory class.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you expect whats not already in @return UnboundedQuantityValue|self?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, @return UnboundedQuantityValue|self is complete, but it's easy to miss. Since we are doing something quite unexpected (returning an incompatible object from a pseudo-constructor), a @warning seems in order.

@brightbyte
Copy link
Copy Markdown

+1 from me, +2 with better documentation.

@thiemowmde
Copy link
Copy Markdown
Contributor Author

Much, much simpler now. The fact that the implementation is split into two classes is considered an implementation detail. It's intended that the classes know each other, in both directions. There should only be one of these static newFromArray constructors.

@brightbyte brightbyte merged commit f3d5e64 into master Aug 3, 2016
@brightbyte brightbyte deleted the quantityBuilder branch August 3, 2016 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants