Jeroen De Dauw has submitted this change and it was merged.

Change subject: Remove usage of ValueFormatters\Result
......................................................................


Remove usage of ValueFormatters\Result

Depends on https://gerrit.wikimedia.org/r/#/c/58882/

Change-Id: I797b81aeca3c493b5ec2049154f8b598231b4cc4
---
M lib/includes/formatters/EntityIdFormatter.php
M lib/includes/formatters/EntityIdLabelFormatter.php
M lib/tests/phpunit/formatters/EntityIdFormatterTest.php
M lib/tests/phpunit/formatters/EntityIdLabelFormatterTest.php
4 files changed, 17 insertions(+), 22 deletions(-)

Approvals:
  Jeroen De Dauw: Verified; Looks good to me, approved



diff --git a/lib/includes/formatters/EntityIdFormatter.php 
b/lib/includes/formatters/EntityIdFormatter.php
index 7131524..0fa8b7a 100644
--- a/lib/includes/formatters/EntityIdFormatter.php
+++ b/lib/includes/formatters/EntityIdFormatter.php
@@ -3,6 +3,7 @@
 namespace Wikibase\Lib;
 
 use InvalidArgumentException;
+use OutOfBoundsException;
 use ValueFormatters\FormatterOptions;
 use ValueFormatters\ValueFormatterBase;
 use ValueFormatters\Result;
@@ -49,7 +50,7 @@
         *
         * @param FormatterOptions $options
         *
-        * @throws \InvalidArgumentException
+        * @throws InvalidArgumentException
         */
        public function __construct( FormatterOptions $options ) {
                parent::__construct( $options );
@@ -70,9 +71,9 @@
         *
         * @param mixed $value The value to format
         *
-        * @throws \InvalidArgumentException
-        *
         * @return Result
+        * @throws InvalidArgumentException
+        * @throws OutOfBoundsException
         */
        public function format( $value ) {
                if ( !( $value instanceof EntityId ) ) {
@@ -80,15 +81,15 @@
                }
 
                $prefixMap = $this->getOption( self::OPT_PREFIX_MAP );
+               $entityType = $value->getEntityType();
 
-               if ( array_key_exists( $value->getEntityType(), $prefixMap ) ) {
+               if ( array_key_exists( $entityType, $prefixMap ) ) {
                        $entityTypePrefix = $prefixMap[$value->getEntityType()];
 
-                       return $this->newSuccess( $entityTypePrefix . 
$value->getNumericId() );
+                       return $entityTypePrefix . $value->getNumericId();
                }
 
-               // TODO: implement: return formatting error
-               return $this->newSuccess( 'TODO: ERROR: entity type not found' 
);
+               throw new OutOfBoundsException( "Entity type '$entityType' not 
found" );
        }
 
 }
diff --git a/lib/includes/formatters/EntityIdLabelFormatter.php 
b/lib/includes/formatters/EntityIdLabelFormatter.php
index 02cf9a0..f744c64 100644
--- a/lib/includes/formatters/EntityIdLabelFormatter.php
+++ b/lib/includes/formatters/EntityIdLabelFormatter.php
@@ -3,6 +3,7 @@
 namespace Wikibase\Lib;
 
 use InvalidArgumentException;
+use RuntimeException;
 use ValueFormatters\FormatterOptions;
 use ValueFormatters\ValueFormatterBase;
 use ValueFormatters\Result;
@@ -96,10 +97,9 @@
         *
         * @param mixed $value The value to format
         *
-        * @throws \InvalidArgumentException
-        *
         * @return Result
-        * @throws \RuntimeException
+        * @throws RuntimeException
+        * @throws InvalidArgumentException
         */
        public function format( $value ) {
                if ( !( $value instanceof EntityId ) ) {
@@ -115,10 +115,10 @@
                                        break;
                                case self::FALLBACK_PREFIXED_ID:
                                        if ( $this->idFormatter === null ) {
-                                               throw new \RuntimeException( 
'Cannot format the id using a prefix without the EntityIdFormatter being set' );
+                                               throw new RuntimeException( 
'Cannot format the id using a prefix without the EntityIdFormatter being set' );
                                        }
 
-                                       $label = $this->idFormatter->format( 
$value )->getValue();
+                                       $label = $this->idFormatter->format( 
$value );
                                        break;
                                default:
                                        // TODO: implement: return formatting 
error
@@ -127,7 +127,7 @@
                }
 
                assert( is_string( $label ) );
-               return $this->newSuccess( $label );
+               return $label;
        }
 
        /**
diff --git a/lib/tests/phpunit/formatters/EntityIdFormatterTest.php 
b/lib/tests/phpunit/formatters/EntityIdFormatterTest.php
index a3267c4..0674ecc 100644
--- a/lib/tests/phpunit/formatters/EntityIdFormatterTest.php
+++ b/lib/tests/phpunit/formatters/EntityIdFormatterTest.php
@@ -84,11 +84,9 @@
                $formatter = $this->newEntityIdFormatter();
 
                $formattingResult = $formatter->format( $entityId );
-               $this->assertInstanceOf( 'ValueFormatters\Result', 
$formattingResult );
-               $this->assertTrue( $formattingResult->isValid(), 'Formatting 
result should be valid' );
 
-               $this->assertInternalType( 'string', 
$formattingResult->getValue() );
-               $this->assertEquals( $expectedString, 
$formattingResult->getValue() );
+               $this->assertInternalType( 'string', $formattingResult );
+               $this->assertEquals( $expectedString, $formattingResult );
        }
 
 }
diff --git a/lib/tests/phpunit/formatters/EntityIdLabelFormatterTest.php 
b/lib/tests/phpunit/formatters/EntityIdLabelFormatterTest.php
index c2d263b..7b9383c 100644
--- a/lib/tests/phpunit/formatters/EntityIdLabelFormatterTest.php
+++ b/lib/tests/phpunit/formatters/EntityIdLabelFormatterTest.php
@@ -133,13 +133,9 @@
                $formatter = new EntityIdLabelFormatter( $formatterOptions, 
$this->newEntityLoader() );
                $formatter->setIdFormatter( $this->newEntityIdFormatter() );
 
-               $formattingResult = $formatter->format( $entityId );
-               $this->assertInstanceOf( 'ValueFormatters\Result', 
$formattingResult );
-               $this->assertTrue( $formattingResult->isValid(), 'Formatting 
result should be valid' );
+               $formattedValue = $formatter->format( $entityId );
 
-               $formattedValue = $formattingResult->getValue();
                $this->assertInternalType( 'string', $formattedValue );
-
                $this->assertEquals( $expectedString, $formattedValue );
        }
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I797b81aeca3c493b5ec2049154f8b598231b4cc4
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <jeroended...@gmail.com>
Gerrit-Reviewer: Jeroen De Dauw <jeroended...@gmail.com>
Gerrit-Reviewer: Tobias Gritschacher <tobias.gritschac...@wikimedia.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to