SerializedEntitySerializer   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 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 0
cbo 2
dl 0
loc 27
ccs 10
cts 10
cp 1
rs 10

3 Methods

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