JsonLdStringFormatter::toJsonLd()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
crap 1
1
<?php
2
3
namespace PPP\Wikidata\ValueFormatters\JsonLd;
4
5
use DataValues\StringValue;
6
use InvalidArgumentException;
7
use stdClass;
8
use ValueFormatters\ValueFormatterBase;
9
10
/**
11
 * @licence AGPLv3+
12
 * @author Thomas Pellissier Tanon
13
 */
14
class JsonLdStringFormatter extends ValueFormatterBase implements JsonLdDataValueFormatter {
15
16
	/**
17
	 * @see ValueFormatter::format
18
	 */
19 1
	public function format($value) {
20 1
		if(!($value instanceof StringValue)) {
21
			throw new InvalidArgumentException('$value is not a StringValue.');
22
		}
23
24 1
		return $this->toJsonLd($value);
25
	}
26
27 1
	private function toJsonLd(StringValue $value) {
28 1
		$literal = new stdClass();
29 1
		$literal->{'@value'} = $value->getValue();
30 1
		return $literal;
31
	}
32
}
33