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

DataValueSerializer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 3
c 4
b 0
f 1
lcom 0
cbo 2
dl 0
loc 33
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A serialize() 0 10 2
A isSerializerFor() 0 3 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