PropertyListSerializer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 4
dl 0
loc 30
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A serialize() 0 7 2
A serializeList() 0 9 2
A serializeElement() 0 8 1
1
<?php
2
3
namespace Queryr\Serialization;
4
5
use Queryr\Resources\PropertyList;
6
use Queryr\Resources\PropertyListElement;
7
use Serializers\Exceptions\UnsupportedObjectException;
8
use Serializers\Serializer;
9
10
/**
11
 * @access private
12
 * @licence GNU GPL v2+
13
 * @author Jeroen De Dauw < [email protected] >
14
 */
15
class PropertyListSerializer implements Serializer {
16
17 2
	public function serialize( $object ) {
18 2
		if ( !( $object instanceof PropertyList ) ) {
19 1
			throw new UnsupportedObjectException( $object, 'Can only serialize instances of PropertyList' );
20
		}
21
22 1
		return $this->serializeList( $object );
23
	}
24
25 1
	private function serializeList( PropertyList $list ) {
26 1
		$serialization = [];
27
28 1
		foreach ( $list->getElements() as $element ) {
29 1
			$serialization[] = $this->serializeElement( $element );
30 1
		}
31
32 1
		return $serialization;
33
	}
34
35 1
	private function serializeElement( PropertyListElement $element ) {
36
		return [
37 1
			'id' => $element->getPropertyId()->getSerialization(),
38 1
			'type' => $element->getPropertyType(),
39 1
			'url' => $element->getApiUrl(),
40 1
			'wikidata_url' => $element->getWikidataUrl(),
41 1
		];
42
	}
43
44
}
45