jenkins-bot has submitted this change and it was merged.
Change subject: Clean up WikibaseValueFormatterBuilders and related
......................................................................
Clean up WikibaseValueFormatterBuilders and related
This is a direct follow up to I4261b3d.
* Type hinted against TypedValueFormatter interface instead of
implementation in PropertyValueSnakFormatter.
* Specific type hints in WikibaseValueFormatterBuilders for private
methods, generic ValueFormatter type hints for interface methods.
* Moved the new test in WikibaseValueFormatterBuildersTest up.
* Added type hints.
* Cleaned some @throws and @see tags.
Change-Id: I77186efbf4aa2e3fe12c0d9c75bac17dc6006ed7
---
M lib/includes/formatters/DispatchingValueFormatter.php
M lib/includes/formatters/PropertyValueSnakFormatter.php
M lib/includes/formatters/WikibaseSnakFormatterBuilders.php
M lib/includes/formatters/WikibaseValueFormatterBuilders.php
M lib/tests/phpunit/formatters/WikibaseValueFormatterBuildersTest.php
5 files changed, 50 insertions(+), 31 deletions(-)
Approvals:
Hoo man: Looks good to me, approved
Unicodesnowman: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/lib/includes/formatters/DispatchingValueFormatter.php
b/lib/includes/formatters/DispatchingValueFormatter.php
index b93f31b..10aae2a 100644
--- a/lib/includes/formatters/DispatchingValueFormatter.php
+++ b/lib/includes/formatters/DispatchingValueFormatter.php
@@ -27,10 +27,9 @@
* Each type ID must be prefixed with either "PT:" for property
data types
* or "VT:" for data value types.
*
- * @throws \InvalidArgumentException
+ * @throws InvalidArgumentException
*/
public function __construct( array $formatters ) {
-
foreach ( $formatters as $type => $formatter ) {
if ( !is_string( $type ) ) {
throw new InvalidArgumentException(
'$formatters must map type IDs to formatters.' );
@@ -50,7 +49,7 @@
}
/**
- * @see ValueFormatter::format().
+ * @see ValueFormatter::format
*
* Formats the given value by finding an appropriate formatter among
the ones supplied
* to the constructor, and applying it.
@@ -59,7 +58,7 @@
* the data type. If none is found, this falls back to finding a
formatter based on the
* value's type.
*
- * @see TypedValueFormatter::formatValue.
+ * @see TypedValueFormatter::formatValue
*
* @param DataValue $value
* @param string $dataTypeId
@@ -75,13 +74,13 @@
}
/**
- * @see ValueFormatter::format().
+ * @see ValueFormatter::format
*
* @since 0.5
*
* @param DataValue $value The value to format
*
- * @throws \DataValues\IllegalValueException
+ * @throws IllegalValueException
* @return string
*/
public function format( $value ) {
diff --git a/lib/includes/formatters/PropertyValueSnakFormatter.php
b/lib/includes/formatters/PropertyValueSnakFormatter.php
index 83d9b35..77f8e3e 100644
--- a/lib/includes/formatters/PropertyValueSnakFormatter.php
+++ b/lib/includes/formatters/PropertyValueSnakFormatter.php
@@ -59,7 +59,7 @@
private $options;
/**
- * @var DispatchingValueFormatter
+ * @var TypedValueFormatter
*/
private $valueFormatter;
@@ -77,7 +77,7 @@
* @param string $format The name of this formatter's output format.
* Use the FORMAT_XXX constants defined in SnakFormatter.
* @param FormatterOptions $options
- * @param DispatchingValueFormatter $valueFormatter
+ * @param TypedValueFormatter $valueFormatter
* @param PropertyDataTypeLookup $typeLookup
* @param DataTypeFactory $dataTypeFactory
*
@@ -86,7 +86,7 @@
public function __construct(
$format,
FormatterOptions $options,
- DispatchingValueFormatter $valueFormatter,
+ TypedValueFormatter $valueFormatter,
PropertyDataTypeLookup $typeLookup,
DataTypeFactory $dataTypeFactory
) {
@@ -276,11 +276,11 @@
}
/**
- * @see ValueFormatter::format().
+ * @see ValueFormatter::format
*
- * Implemented by delegating to the DispatchingValueFormatter passed to
the constructor.
+ * Implemented by delegating to the TypedValueFormatter passed to the
constructor.
*
- * @see TypedValueFormatter::formatValue.
+ * @see TypedValueFormatter::formatValue
*
* @param DataValue $value
* @param string $dataTypeId
@@ -310,7 +310,7 @@
/**
* Checks whether the given snak's type is 'value'.
*
- * @see SnakFormatter::canFormatSnak()
+ * @see SnakFormatter::canFormatSnak
*
* @param Snak $snak
*
diff --git a/lib/includes/formatters/WikibaseSnakFormatterBuilders.php
b/lib/includes/formatters/WikibaseSnakFormatterBuilders.php
index 245b18a..16ae33d 100644
--- a/lib/includes/formatters/WikibaseSnakFormatterBuilders.php
+++ b/lib/includes/formatters/WikibaseSnakFormatterBuilders.php
@@ -3,6 +3,7 @@
namespace Wikibase\Lib;
use DataTypes\DataTypeFactory;
+use Message;
use ValueFormatters\FormatterOptions;
use ValueFormatters\ValueFormatter;
use Wikibase\DataModel\Entity\PropertyDataTypeLookup;
@@ -106,11 +107,12 @@
* @param string $key
* @param string $lang
*
- * @return \Message
+ * @return Message
*/
private function getMessage( $key, $lang ) {
$msg = wfMessage( $key );
$msg = $msg->inLanguage( $lang );
return $msg;
}
+
}
diff --git a/lib/includes/formatters/WikibaseValueFormatterBuilders.php
b/lib/includes/formatters/WikibaseValueFormatterBuilders.php
index 996e9ff..2fceb4a 100644
--- a/lib/includes/formatters/WikibaseValueFormatterBuilders.php
+++ b/lib/includes/formatters/WikibaseValueFormatterBuilders.php
@@ -521,7 +521,7 @@
*
* @param FormatterOptions $options
*
- * @return ValueFormatter
+ * @return EntityIdHtmlLinkFormatter
*/
private function newEntityIdHtmlFormatter( FormatterOptions $options ) {
$labelLookup = $this->labelLookupFactory->getLabelLookup(
$options );
@@ -589,7 +589,7 @@
* @param ValueFormatter[] $formatters
* @param string $escape The escape callback, e.g. 'htmlspecialchars'
or 'wfEscapeWikitext'.
*
- * @return array
+ * @return ValueFormatter[]
*/
public function makeEscapingFormatters( array $formatters, $escape ) {
$escapingFormatters = array();
diff --git
a/lib/tests/phpunit/formatters/WikibaseValueFormatterBuildersTest.php
b/lib/tests/phpunit/formatters/WikibaseValueFormatterBuildersTest.php
index 964d01b..ddfb521 100644
--- a/lib/tests/phpunit/formatters/WikibaseValueFormatterBuildersTest.php
+++ b/lib/tests/phpunit/formatters/WikibaseValueFormatterBuildersTest.php
@@ -2,12 +2,13 @@
namespace Wikibase\Lib\Test;
-use Language;
-use Title;
+use DataValues\DataValue;
use DataValues\MonolingualTextValue;
use DataValues\QuantityValue;
use DataValues\StringValue;
use DataValues\TimeValue;
+use Language;
+use Title;
use ValueFormatters\FormatterOptions;
use ValueFormatters\StringFormatter;
use ValueFormatters\TimeFormatter;
@@ -16,13 +17,14 @@
use Wikibase\DataModel\Entity\EntityIdValue;
use Wikibase\DataModel\Entity\ItemId;
use Wikibase\DataModel\Entity\PropertyId;
+use Wikibase\LanguageFallbackChain;
use Wikibase\LanguageFallbackChainFactory;
use Wikibase\Lib\EntityIdFormatter;
use Wikibase\Lib\FormatterLabelLookupFactory;
use Wikibase\Lib\OutputFormatValueFormatterFactory;
use Wikibase\Lib\SnakFormatter;
-use Wikibase\Lib\WikibaseValueFormatterBuilders;
use Wikibase\Lib\Store\EntityTitleLookup;
+use Wikibase\Lib\WikibaseValueFormatterBuilders;
/**
* @covers Wikibase\Lib\WikibaseValueFormatterBuilders
@@ -43,8 +45,8 @@
}
/**
- * @param EntityId $entityId The Id of an entity to use for all entity
lookups
* @param EntityTitleLookup|null $entityTitleLookup
+ *
* @return WikibaseValueFormatterBuilders
*/
private function newWikibaseValueFormatterBuilders( EntityTitleLookup
$entityTitleLookup = null ) {
@@ -101,7 +103,13 @@
/**
* @dataProvider buildDispatchingValueFormatterProvider
*/
- public function testBuildDispatchingValueFormatter( $format, $options,
$value, $expected, $dataTypeId = null ) {
+ public function testBuildDispatchingValueFormatter(
+ $format,
+ FormatterOptions $options,
+ DataValue $value,
+ $expected,
+ $dataTypeId = null
+ ) {
$builders = $this->newWikibaseValueFormatterBuilders(
$this->newEntityTitleLookup() );
$factory = new OutputFormatValueFormatterFactory(
$builders->getValueFormatterBuildersForFormats() );
@@ -144,6 +152,13 @@
'/^<a\b[^>]* href="[^"]*\bQ5">Label for
Q5<\/a>.*$/', // compare mock object created in newBuilders()
'wikibase-item'
),
+ 'property link' => array(
+ SnakFormatter::FORMAT_HTML,
+ $this->newFormatterOptions(),
+ new EntityIdValue( new PropertyId( 'P5' ) ),
+ '/^<a\b[^>]* href="[^"]*\bP5">Label for
P5<\/a>.*$/',
+ 'wikibase-property'
+ ),
'diff <url>' => array(
SnakFormatter::FORMAT_HTML_DIFF,
$this->newFormatterOptions(),
@@ -162,13 +177,6 @@
new StringValue( 'Example.jpg' ),
'@^<a class="extiw"
href="//commons\\.wikimedia\\.org/wiki/File:Example\\.jpg">Example\\.jpg</a>$@',
'commonsMedia'
- ),
- 'property link' => array(
- SnakFormatter::FORMAT_HTML,
- $this->newFormatterOptions(),
- new EntityIdValue( new PropertyId( 'P5' ) ),
- '/^<a\b[^>]* href="[^"]*\bP5">Label for
P5<\/a>.*$/',
- 'wikibase-property'
),
'a month in 1920' => array(
SnakFormatter::FORMAT_HTML,
@@ -224,7 +232,13 @@
*
* @dataProvider buildDispatchingValueFormatterNoTitleLookupProvider
*/
- public function testBuildDispatchingValueFormatter_noTitleLookup(
$format, $options, $value, $expected, $dataTypeId = null ) {
+ public function testBuildDispatchingValueFormatter_noTitleLookup(
+ $format,
+ FormatterOptions $options,
+ DataValue $value,
+ $expected,
+ $dataTypeId = null
+ ) {
$builders = $this->newWikibaseValueFormatterBuilders();
$factory = new OutputFormatValueFormatterFactory(
$builders->getValueFormatterBuildersForFormats() );
@@ -255,7 +269,11 @@
/**
* @dataProvider
buildDispatchingValueFormatterProvider_LabelLookupOption
*/
- public function testBuildDispatchingValueFormatter_LabelLookupOption(
$options, ItemId $value, $expected ) {
+ public function testBuildDispatchingValueFormatter_LabelLookupOption(
+ FormatterOptions $options,
+ ItemId $value,
+ $expected
+ ) {
$builders = $this->newWikibaseValueFormatterBuilders(
$this->newEntityTitleLookup() );
$factory = new OutputFormatValueFormatterFactory(
$builders->getValueFormatterBuildersForFormats() );
@@ -580,7 +598,7 @@
}
if ( $expectedFallback !== null ) {
- /* @var LanguageFallbackChain $languageFallback */
+ /** @var LanguageFallbackChain $languageFallback */
$languageFallback = $options->getOption( 'languages' );
$languages = $languageFallback->getFallbackChain();
$lang = $languages[0]->getLanguage()->getCode();
--
To view, visit https://gerrit.wikimedia.org/r/181094
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I77186efbf4aa2e3fe12c0d9c75bac17dc6006ed7
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: Unicodesnowman <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits