SentenceNodeSerializer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 27
c 0
b 0
f 0
ccs 10
cts 10
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isSerializerFor() 0 3 2
A serialize() 0 7 2
A getSerialization() 0 6 1
1
<?php
2
3
namespace PPP\DataModel\Serializers;
4
5
use PPP\DataModel\SentenceNode;
6
use Serializers\DispatchableSerializer;
7
use Serializers\Exceptions\UnsupportedObjectException;
8
9
/**
10
 * @licence AGPLv3+
11
 * @author Thomas Pellissier Tanon
12
 */
13
class SentenceNodeSerializer implements DispatchableSerializer {
14
15
	/**
16
	 * @see DispatchableSerializer::isSerializerFor
17
	 */
18 6
	public function isSerializerFor($object) {
19 6
		return is_object($object) && $object instanceof SentenceNode;
20
	}
21
22
	/**
23
	 * @see Serializer::serialize
24
	 */
25 3
	public function serialize($object) {
26 3
		if(!$this->isSerializerFor($object)) {
27 2
			throw new UnsupportedObjectException($object, 'SentenceNodeSerializer can only serialize SentenceNode objects.');
28
		}
29
30 1
		return $this->getSerialization($object);
31
	}
32
33 1
	private function getSerialization(SentenceNode $node) {
34
		return array(
35 1
			'type' => 'sentence',
36 1
			'value' => $node->getValue()
37 1
		);
38
	}
39
}