SimpleStatementSerializer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 24
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A serialize() 0 20 4
1
<?php
2
3
namespace Queryr\Serialization;
4
5
use Queryr\Resources\SimpleStatement;
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 SimpleStatementSerializer implements Serializer {
15
16
	public function serialize( $simpleStatement ) {
17
		if ( !( $simpleStatement instanceof SimpleStatement ) ) {
18
			throw new UnsupportedObjectException( $simpleStatement, 'Can only serialize instances of SimpleStatement' );
19
		}
20
21
		$propertyValue = [
22
			'value' => $simpleStatement->values[0]->getArrayValue(),
23
			'type' => $simpleStatement->valueType
24
		];
25
26
		if ( count( $simpleStatement->values ) > 1 ) {
27
			$propertyValue['values'] = [];
28
29
			foreach ( $simpleStatement->values as $value ) {
30
				$propertyValue['values'][] = $value->getArrayValue();
31
			}
32
		}
33
34
		return $propertyValue;
35
	}
36
37
}