ItemTypeSerializer::serialize()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Queryr\Serialization;
4
5
use Queryr\Resources\ItemType;
6
use Serializers\Exceptions\UnsupportedObjectException;
7
use Serializers\Serializer;
8
9
/**
10
 * @access private
11
 * @licence GNU GPL v2+
12
 * @author Jeroen De Dauw < [email protected] >
13
 */
14
class ItemTypeSerializer implements Serializer {
15
16 2
	public function serialize( $object ) {
17 2
		if ( !( $object instanceof ItemType ) ) {
18 1
			throw new UnsupportedObjectException( $object, 'Can only serialize instances of ItemType' );
19
		}
20
21 1
		return $this->serializeItemType( $object );
22
	}
23
24 1
	private function serializeItemType( ItemType $itemType ) {
25
		return [
26 1
			'label' => $itemType->getLabel(),
27 1
			'id' => $itemType->getItemId()->getSerialization(),
28 1
			'url' => $itemType->getApiUrl(),
29 1
			'wikidata_url' => $itemType->getWikidataUrl(),
30 1
		];
31
	}
32
33
}
34