Jeroen De Dauw has uploaded a new change for review.
https://gerrit.wikimedia.org/r/58882
Change subject: Remove ValueFormatters Result interface
......................................................................
Remove ValueFormatters Result interface
Change-Id: I5015813f49075b7de85d967bb9d99d9138df7899
---
M ValueFormatters/ValueFormatters.classes.php
A ValueFormatters/includes/FormattingException.php
M ValueFormatters/includes/Result.php
M ValueFormatters/includes/ValueFormatter.php
M ValueFormatters/includes/ValueFormatterBase.php
M ValueFormatters/includes/formatters/GeoCoordinateFormatter.php
M ValueFormatters/includes/formatters/IriFormatter.php
M ValueFormatters/includes/formatters/StringFormatter.php
M ValueFormatters/tests/ValueFormatterTestBase.php
M ValueParsers/includes/ParseException.php
10 files changed, 42 insertions(+), 52 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DataValues
refs/changes/82/58882/1
diff --git a/ValueFormatters/ValueFormatters.classes.php
b/ValueFormatters/ValueFormatters.classes.php
index b42b194..6ea051f 100644
--- a/ValueFormatters/ValueFormatters.classes.php
+++ b/ValueFormatters/ValueFormatters.classes.php
@@ -28,8 +28,7 @@
*/
return array(
'ValueFormatters\FormatterOptions' => 'includes/FormatterOptions.php',
- 'ValueFormatters\Result' => 'includes/Result.php',
- 'ValueFormatters\ResultObject' => 'includes/Result.php',
+ 'ValueFormatters\FormattingException' =>
'includes/FormattingException.php',
'ValueFormatters\ValueFormatter' => 'includes/ValueFormatter.php',
'ValueFormatters\ValueFormatterBase' =>
'includes/ValueFormatterBase.php',
'ValueFormatters\ValueFormatterFactory' =>
'includes/ValueFormatterFactory.php',
diff --git a/ValueFormatters/includes/FormattingException.php
b/ValueFormatters/includes/FormattingException.php
new file mode 100644
index 0000000..5f7fd89
--- /dev/null
+++ b/ValueFormatters/includes/FormattingException.php
@@ -0,0 +1,31 @@
+<?php
+
+namespace ValueParsers;
+
+/**
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @since 0.1
+ *
+ * @file
+ * @ingroup ValueFormatters
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class FormattingException extends \RuntimeException {
+
+}
diff --git a/ValueFormatters/includes/Result.php
b/ValueFormatters/includes/Result.php
index b4ccbdc..86394c9 100644
--- a/ValueFormatters/includes/Result.php
+++ b/ValueFormatters/includes/Result.php
@@ -9,8 +9,6 @@
* Interface for value parser results.
* Immutable.
*
- * TODO: error support
- *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@@ -27,6 +25,7 @@
* http://www.gnu.org/copyleft/gpl.html
*
* @since 0.1
+ * @deprecated
*
* @file
* @ingroup ValueFormatters
diff --git a/ValueFormatters/includes/ValueFormatter.php
b/ValueFormatters/includes/ValueFormatter.php
index 51cf99e..b97c9bb 100644
--- a/ValueFormatters/includes/ValueFormatter.php
+++ b/ValueFormatters/includes/ValueFormatter.php
@@ -43,7 +43,7 @@
*
* @param mixed $value The value to format
*
- * @return Result
+ * @return mixed
*/
public function format( $value );
diff --git a/ValueFormatters/includes/ValueFormatterBase.php
b/ValueFormatters/includes/ValueFormatterBase.php
index c6eef96..f39fbb1 100644
--- a/ValueFormatters/includes/ValueFormatterBase.php
+++ b/ValueFormatters/includes/ValueFormatterBase.php
@@ -49,17 +49,6 @@
}
/**
- * @since 0.1
- *
- * @param mixed $value
- *
- * @return Result
- */
- protected function newSuccess( $value ) {
- return Result::newSuccess( $value );
- }
-
- /**
* Shortcut to $this->options->getOption.
*
* @since 0.1
diff --git a/ValueFormatters/includes/formatters/GeoCoordinateFormatter.php
b/ValueFormatters/includes/formatters/GeoCoordinateFormatter.php
index 6f28a11..52787cd 100644
--- a/ValueFormatters/includes/formatters/GeoCoordinateFormatter.php
+++ b/ValueFormatters/includes/formatters/GeoCoordinateFormatter.php
@@ -99,7 +99,7 @@
*
* @param mixed $value The value to format
*
- * @return Result
+ * @return string
* @throws InvalidArgumentException
*/
public function format( $value ) {
@@ -113,7 +113,7 @@
$formatted = implode( $this->getOption(
self::OPT_SEPARATOR_SYMBOL ) . ' ', array( $latitude, $longitude ) );
- return $this->newSuccess( $formatted );
+ return $formatted;
}
/**
diff --git a/ValueFormatters/includes/formatters/IriFormatter.php
b/ValueFormatters/includes/formatters/IriFormatter.php
index a24e15f..4344269 100644
--- a/ValueFormatters/includes/formatters/IriFormatter.php
+++ b/ValueFormatters/includes/formatters/IriFormatter.php
@@ -40,7 +40,7 @@
*
* @param mixed $dataValue value to format
*
- * @return Result
+ * @return string
* @throws InvalidArgumentException
*/
public function format( $dataValue ) {
@@ -53,7 +53,7 @@
. ( $dataValue->getQuery() === '' ? '' : '?' .
$dataValue->getQuery() )
. ( $dataValue->getFragment() === '' ? '' : '#' .
$dataValue->getFragment() );
- return $this->newSuccess( $formatted );
+ return $formatted;
}
}
diff --git a/ValueFormatters/includes/formatters/StringFormatter.php
b/ValueFormatters/includes/formatters/StringFormatter.php
index 7990660..09e287c 100644
--- a/ValueFormatters/includes/formatters/StringFormatter.php
+++ b/ValueFormatters/includes/formatters/StringFormatter.php
@@ -40,7 +40,7 @@
*
* @param mixed $dataValue value to format
*
- * @return Result
+ * @return string
* @throws InvalidArgumentException
*/
public function format( $dataValue ) {
@@ -48,9 +48,7 @@
throw new InvalidArgumentException( 'DataValue is not a
StringValue.' );
}
- $formatted = $dataValue->getValue();
-
- return $this->newSuccess( $formatted );
+ return $dataValue->getValue();
}
}
diff --git a/ValueFormatters/tests/ValueFormatterTestBase.php
b/ValueFormatters/tests/ValueFormatterTestBase.php
index 1489c33..be394fa 100644
--- a/ValueFormatters/tests/ValueFormatterTestBase.php
+++ b/ValueFormatters/tests/ValueFormatterTestBase.php
@@ -75,24 +75,9 @@
* @param mixed $value
* @param mixed $expected
* @param FormatterOptions|null $options
- */
- public function testValidFormat( $value, $expected, FormatterOptions
$options = null ) {
- $this->doTestFormat(
- $value,
- \ValueFormatters\Result::newSuccess( $expected ),
- $options
- );
- }
-
- /**
- * @since 0.1
- *
- * @param mixed $value
- * @param Result $expected
- * @param FormatterOptions|null $options
* @param ValueFormatter|null $formatter
*/
- protected function doTestFormat( $value, Result $expected,
FormatterOptions $options = null, ValueFormatter $formatter = null ) {
+ public function testValidFormat( $value, $expected, FormatterOptions
$options = null, ValueFormatter $formatter = null ) {
if ( $options === null ) {
$options = new FormatterOptions();
}
@@ -101,16 +86,7 @@
$formatter = $this->getInstance( $options );
}
- $result = $formatter->format( $value );
-
- $this->assertEquals( $expected->isValid(), $result->isValid() );
-
- if ( $expected->isValid() ) {
- $this->assertEquals( $expected->getValue(),
$result->getValue() );
- }
- else {
- $this->assertException( function() use ( $result ) {
$result->getValue(); } );
- }
+ $this->assertEquals( $expected, $formatter->format( $value ) );
}
}
diff --git a/ValueParsers/includes/ParseException.php
b/ValueParsers/includes/ParseException.php
index d57dc8b..a6cf6ac 100644
--- a/ValueParsers/includes/ParseException.php
+++ b/ValueParsers/includes/ParseException.php
@@ -3,8 +3,6 @@
namespace ValueParsers;
/**
- * Parse exception
- *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
--
To view, visit https://gerrit.wikimedia.org/r/58882
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5015813f49075b7de85d967bb9d99d9138df7899
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DataValues
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits