JsonLdItemFormatter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 90.91%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A format() 0 7 2
A toJsonLd() 0 4 1
1
<?php
2
3
namespace PPP\Wikidata\ValueFormatters\JsonLd\Entity;
4
5
use InvalidArgumentException;
6
use ValueFormatters\FormatterOptions;
7
use ValueFormatters\ValueFormatter;
8
use ValueFormatters\ValueFormatterBase;
9
use Wikibase\DataModel\Entity\Item;
10
11
/**
12
 * @licence AGPLv3+
13
 * @author Thomas Pellissier Tanon
14
 * @todo output sitelinks
15
 */
16
class JsonLdItemFormatter extends ValueFormatterBase {
17
18
	/**
19
	 * @var ValueFormatter
20
	 */
21
	private $entityFormatter;
22
23
	/**
24
	 * @param ValueFormatter $entityFormatter
25
	 * @param FormatterOptions $options
26
	 */
27 1
	public function __construct(ValueFormatter $entityFormatter, FormatterOptions $options) {
28 1
		$this->entityFormatter = $entityFormatter;
29
30 1
		parent::__construct($options);
31 1
	}
32
33
	/**
34
	 * @see ValueFormatter::format
35
	 */
36 1
	public function format($value) {
37 1
		if(!($value instanceof Item)) {
38
			throw new InvalidArgumentException('$value is not an Item.');
39
		}
40
41 1
		return $this->toJsonLd($value);
42
	}
43
44 1
	private function toJsonLd(Item $item) {
45 1
		$resource = $this->entityFormatter->format($item);
46 1
		return $resource;
47
	}
48
}
49