Passed
Pull Request — master (#20)
by no
03:23 queued 01:53
created

DataValueSerializer::getSerializedDataValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace DataValues\Serializers;
4
5
use DataValues\DataValue;
6
use Serializers\DispatchableSerializer;
7
use Serializers\Exceptions\UnsupportedObjectException;
8
9
/**
10
 * @since 0.1
11
 *
12
 * @license GPL-2.0+
13
 * @author Jeroen De Dauw < [email protected] >
14
 */
15
class DataValueSerializer implements DispatchableSerializer {
16
17
	/**
18
	 * @see Serializer::serialize
19
	 *
20
	 * @param DataValue $object
21
	 *
22
	 * @throws UnsupportedObjectException
23
	 * @return array
24
	 */
25
	public function serialize( $object ) {
26
		if ( $this->isSerializerFor( $object ) ) {
27
			return $object->toArray();
28
		}
29
30
		throw new UnsupportedObjectException(
31
			$object,
32
			'DataValueSerializer can only serialize DataValue objects'
33
		);
34
	}
35
36
	/**
37
	 * @see DispatchableSerializer::isSerializerFor
38
	 *
39
	 * @param mixed $object
40
	 *
41
	 * @return bool
42
	 */
43
	public function isSerializerFor( $object ) {
44
		return $object instanceof DataValue;
45
	}
46
47
}
48