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

StringFormatter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 19
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A format() 0 7 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