SentenceNodeSerializer::getSerialization()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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