Thiemo Mättig (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/371589 )
Change subject: Remove quite a lot of unused code from PropertyValueSnakFormatter ...................................................................... Remove quite a lot of unused code from PropertyValueSnakFormatter Change-Id: I5f31c7fbba031f37edd23b6e55ee7f7236870f26 --- M lib/includes/Formatters/OutputFormatSnakFormatterFactory.php M lib/includes/Formatters/PropertyValueSnakFormatter.php M lib/includes/Formatters/WikibaseSnakFormatterBuilders.php M lib/tests/phpunit/Formatters/PropertyValueSnakFormatterTest.php 4 files changed, 15 insertions(+), 66 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/89/371589/1 diff --git a/lib/includes/Formatters/OutputFormatSnakFormatterFactory.php b/lib/includes/Formatters/OutputFormatSnakFormatterFactory.php index afb0304..0e0c3e9 100644 --- a/lib/includes/Formatters/OutputFormatSnakFormatterFactory.php +++ b/lib/includes/Formatters/OutputFormatSnakFormatterFactory.php @@ -100,7 +100,6 @@ $valueFormatter = $this->valueFormatterFactory->getValueFormatter( $format, $options ); $valueSnakFormatter = new PropertyValueSnakFormatter( $format, - $options, $valueFormatter, $this->propertyDataTypeLookup, $this->dataTypeFactory diff --git a/lib/includes/Formatters/PropertyValueSnakFormatter.php b/lib/includes/Formatters/PropertyValueSnakFormatter.php index 473762a..231ef61 100644 --- a/lib/includes/Formatters/PropertyValueSnakFormatter.php +++ b/lib/includes/Formatters/PropertyValueSnakFormatter.php @@ -6,10 +6,8 @@ use DataValues\DataValue; use DataValues\UnDeserializableValue; use InvalidArgumentException; -use Message; use OutOfBoundsException; use ValueFormatters\Exceptions\MismatchingDataValueTypeException; -use ValueFormatters\FormatterOptions; use ValueFormatters\FormattingException; use ValueFormatters\ValueFormatter; use Wikibase\DataModel\Services\Lookup\PropertyDataTypeLookup; @@ -33,11 +31,6 @@ private $format; /** - * @var FormatterOptions - */ - private $options; - - /** * @var ValueFormatter */ private $valueFormatter; @@ -55,7 +48,6 @@ /** * @param string $format The name of this formatter's output format. * Use the FORMAT_XXX constants defined in SnakFormatter. - * @param FormatterOptions|null $options * @param ValueFormatter $valueFormatter * @param PropertyDataTypeLookup $typeLookup * @param DataTypeFactory $dataTypeFactory @@ -64,7 +56,6 @@ */ public function __construct( $format, - FormatterOptions $options = null, ValueFormatter $valueFormatter, PropertyDataTypeLookup $typeLookup, DataTypeFactory $dataTypeFactory @@ -74,7 +65,6 @@ } $this->format = $format; - $this->options = $options ?: new FormatterOptions(); $this->valueFormatter = $valueFormatter; $this->typeLookup = $typeLookup; $this->dataTypeFactory = $dataTypeFactory; @@ -100,7 +90,6 @@ throw new InvalidArgumentException( "Not a PropertyValueSnak: " . get_class( $snak ) ); } - $propertyType = null; $value = $snak->getDataValue(); try { @@ -112,46 +101,17 @@ throw new FormattingException( $ex->getMessage(), 0, $ex ); } - $this->checkValueType( $value, $expectedDataValueType ); - - return $this->formatValue( $value, $propertyType ); - } - - /** - * @param DataValue $value - * - * @return boolean - */ - private function isUnDeserializableValue( DataValue $value ) { - return $value->getType() === UnDeserializableValue::getType(); - } - - /** - * @param DataValue $value - * @param string $expectedDataValueType - * - * @throws PropertyDataTypeLookupException - * @throws MismatchingDataValueTypeException - * @return Message|null - */ - private function checkValueType( DataValue $value, $expectedDataValueType ) { - $warning = null; - - if ( $this->isUnDeserializableValue( $value ) ) { + if ( $expectedDataValueType !== $value->getType() ) { throw new MismatchingDataValueTypeException( $expectedDataValueType, $value->getType(), - 'Encountered undeserializable value' - ); - } elseif ( $expectedDataValueType !== $value->getType() ) { - throw new MismatchingDataValueTypeException( - $expectedDataValueType, - $value->getType(), - 'The DataValue\'s type mismatches the property\'s DataType.' + $value instanceof UnDeserializableValue + ? 'Encountered undeserializable value' + : 'The DataValue\'s type mismatches the property\'s DataType.' ); } - return $warning; + return $this->formatValue( $value, $propertyType ); } /** @@ -170,24 +130,22 @@ * Calls the TypedValueFormatter passed to the constructor. * * @param DataValue $value - * @param string|null $dataTypeId + * @param string $dataTypeId * * @throws FormattingException * @return string Either plain text, wikitext or HTML, depending on the ValueFormatter * provided. */ - private function formatValue( DataValue $value, $dataTypeId = null ) { - if ( !$this->isUnDeserializableValue( $value ) ) { - if ( $this->valueFormatter instanceof TypedValueFormatter ) { - $text = $this->valueFormatter->formatValue( $value, $dataTypeId ); - } else { - $text = $this->valueFormatter->format( $value ); - } - } else { - $text = ''; + private function formatValue( DataValue $value, $dataTypeId ) { + if ( $value instanceof UnDeserializableValue ) { + return ''; } - return $text; + if ( $this->valueFormatter instanceof TypedValueFormatter ) { + return $this->valueFormatter->formatValue( $value, $dataTypeId ); + } else { + return $this->valueFormatter->format( $value ); + } } /** diff --git a/lib/includes/Formatters/WikibaseSnakFormatterBuilders.php b/lib/includes/Formatters/WikibaseSnakFormatterBuilders.php index 9a7c227..114aeb6 100644 --- a/lib/includes/Formatters/WikibaseSnakFormatterBuilders.php +++ b/lib/includes/Formatters/WikibaseSnakFormatterBuilders.php @@ -95,7 +95,6 @@ if ( $format === SnakFormatter::FORMAT_PLAIN ) { return new PropertyValueSnakFormatter( $format, - $options, $this->valueFormatterBuilders->newStringFormatter( $format, $options ), $this->dataTypeLookup, $this->dataTypeFactory diff --git a/lib/tests/phpunit/Formatters/PropertyValueSnakFormatterTest.php b/lib/tests/phpunit/Formatters/PropertyValueSnakFormatterTest.php index eb10ae9..b581c04 100644 --- a/lib/tests/phpunit/Formatters/PropertyValueSnakFormatterTest.php +++ b/lib/tests/phpunit/Formatters/PropertyValueSnakFormatterTest.php @@ -113,13 +113,8 @@ $typeLookup = $this->getMockDataTypeLookup( $dataType ); $typeFactory = $this->getMockDataTypeFactory( $dataType, $valueType ); - $options = new FormatterOptions( [ - PropertyValueSnakFormatter::OPT_LANG => 'en', - ] ); - $formatter = new PropertyValueSnakFormatter( $targetFormat, - $options, $formatter, $typeLookup, $typeFactory @@ -237,9 +232,7 @@ $valueFormatter = new DispatchingValueFormatter( [] ); - $options = new FormatterOptions( [] ); - - $formatter = new PropertyValueSnakFormatter( $format, $options, $valueFormatter, $typeLookup, $typeFactory ); + $formatter = new PropertyValueSnakFormatter( $format, $valueFormatter, $typeLookup, $typeFactory ); return $formatter; } -- To view, visit https://gerrit.wikimedia.org/r/371589 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I5f31c7fbba031f37edd23b6e55ee7f7236870f26 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits