wikimedia/mediawiki-extensions-Wikibase

View on GitHub
lib/includes/Formatters/MonolingualTextFormatter.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace Wikibase\Lib\Formatters;

use DataValues\MonolingualTextValue;
use InvalidArgumentException;
use ValueFormatters\ValueFormatter;

/**
 * @license GPL-2.0-or-later
 * @author Daniel Kinzler
 */
class MonolingualTextFormatter implements ValueFormatter {

    /**
     * @see ValueFormatter::format
     *
     * @param MonolingualTextValue $value
     *
     * @throws InvalidArgumentException
     * @return string Text
     */
    public function format( $value ) {
        if ( !( $value instanceof MonolingualTextValue ) ) {
            throw new InvalidArgumentException( 'Data value type mismatch. Expected a MonolingualTextValue.' );
        }

        return $value->getText();
    }

}