Completed
Pull Request — master (#47)
by no
17:11 queued 15:26
created

StringFormatter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

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
 * 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