Completed
Pull Request — master (#47)
by no
17:11 queued 15:26
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
 * Formatter for string values
10
 *
11
 * @since 0.1
12
 *
13
 * @license GPL-2.0+
14
 * @author Katie Filbert < [email protected] >
15
 */
16
class StringFormatter extends ValueFormatterBase {
17
18
	/**
19
	 * @see ValueFormatter::format
20
	 *
21
	 * @param StringValue $dataValue
22
	 *
23
	 * @throws InvalidArgumentException
24
	 * @return string Text
25
	 */
26 8
	public function format( $dataValue ) {
27 8
		if ( !( $dataValue instanceof StringValue ) ) {
28 3
			throw new InvalidArgumentException( 'Data value type mismatch. Expected a StringValue.' );
29
		}
30
31 5
		return $dataValue->getValue();
32
	}
33
34
}
35