Completed
Push — master ( 3d831c...fcc0b1 )
by Jeroen De
07:01 queued 02:46
created

StringFormatter::format()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
3
namespace ValueFormatters;
4
5
use DataValues\StringValue;
6
use InvalidArgumentException;
7
8
/**
9
 * Trivial formatter for StringValue objects that does nothing but returning the string value as it
10
 * is.
11
 *
12
 * @since 0.1
13
 *
14
 * @license GPL-2.0+
15
 * @author Katie Filbert < [email protected] >
16
 */
17
class StringFormatter implements ValueFormatter {
18
19
	/**
20
	 * @see ValueFormatter::format
21
	 *
22
	 * @param StringValue $dataValue
23
	 *
24
	 * @throws InvalidArgumentException
25
	 * @return string Text
26
	 */
27 8
	public function format( $dataValue ) {
28 8
		if ( !( $dataValue instanceof StringValue ) ) {
29 3
			throw new InvalidArgumentException( 'Data value type mismatch. Expected a StringValue.' );
30
		}
31
32 5
		return $dataValue->getValue();
33
	}
34
35
}
36