SimplePropertySerializer::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 3
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
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
}