forked from DataValues/Common
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringFormatter.php
More file actions
37 lines (30 loc) · 761 Bytes
/
StringFormatter.php
File metadata and controls
37 lines (30 loc) · 761 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
declare( strict_types = 1 );
namespace ValueFormatters;
use DataValues\StringValue;
use InvalidArgumentException;
/**
* Trivial formatter for StringValue objects that does nothing but returning the string value as it
* is.
*
* @since 0.1
*
* @license GPL-2.0-or-later
* @author Katie Filbert < aude.wiki@gmail.com >
*/
class StringFormatter implements ValueFormatter {
/**
* @see ValueFormatter::format
*
* @param StringValue $dataValue
*
* @throws InvalidArgumentException
* @return string Text
*/
public function format( $dataValue ) {
if ( !( $dataValue instanceof StringValue ) ) {
throw new InvalidArgumentException( 'Data value type mismatch. Expected a StringValue.' );
}
return $dataValue->getValue();
}
}