JsonLdMonolingualTextFormatter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 20
ccs 8
cts 9
cp 0.8889
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A format() 0 7 2
A toJsonLd() 0 6 1
1
<?php
2
3
namespace PPP\Wikidata\ValueFormatters\JsonLd;
4
5
use DataValues\MonolingualTextValue;
6
use InvalidArgumentException;
7
use stdClass;
8
use ValueFormatters\ValueFormatterBase;
9
10
/**
11
 * @licence AGPLv3+
12
 * @author Thomas Pellissier Tanon
13
 */
14
class JsonLdMonolingualTextFormatter extends ValueFormatterBase implements JsonLdDataValueFormatter {
15
16
	/**
17
	 * @see ValueFormatter::format
18
	 */
19 1
	public function format($value) {
20 1
		if(!($value instanceof MonolingualTextValue)) {
21
			throw new InvalidArgumentException('$value is not a MonolingualTextValue.');
22
		}
23
24 1
		return $this->toJsonLd($value);
25
	}
26
27 1
	private function toJsonLd(MonolingualTextValue $value) {
28 1
		$literal = new stdClass();
29 1
		$literal->{'@language'} = $value->getLanguageCode();
30 1
		$literal->{'@value'} = $value->getText();
31 1
		return $literal;
32
	}
33
}
34