SimplePropertySerializer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 35
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A serialize() 0 9 2
A serializeProperty() 0 7 1
1
<?php
2
3
namespace Queryr\Serialization;
4
5
use Queryr\Resources\SimpleProperty;
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 SimplePropertySerializer implements Serializer {
15
16
	/**
17
	 * @var Serializer
18
	 */
19
	private $foundationalSerializer;
20
21
	/**
22
	 * @var SimpleProperty
23
	 */
24
	private $property;
25
26 2
	public function __construct( Serializer $foundationalSerializer ) {
27 2
		$this->foundationalSerializer = $foundationalSerializer;
28 2
	}
29
30 2
	public function serialize( $object ) {
31 2
		if ( !( $object instanceof SimpleProperty ) ) {
32 1
			throw new UnsupportedObjectException( $object, 'Can only serialize instances of SimpleProperty' );
33
		}
34
35 1
		$this->property = $object;
36
37 1
		return $this->serializeProperty();
38
	}
39
40 1
	private function serializeProperty() {
41 1
		$serialization = $this->foundationalSerializer->serialize( $this->property );
42
43 1
		$serialization['type'] = $this->property->type;
44
45 1
		return $serialization;
46
	}
47
48
}