Passed
Push — dispatchEntityId ( b07053...245111 )
by no
07:01 queued 04:24
created

LegacyEntityDeserializer::isDeserializerFor()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
3
namespace Wikibase\InternalSerialization\Deserializers;
4
5
use Deserializers\Deserializer;
6
use Deserializers\Exceptions\DeserializationException;
7
use Wikibase\DataModel\Entity\EntityDocument;
8
9
/**
10
 * @licence GNU GPL v2+
11
 * @author Jeroen De Dauw < [email protected] >
12
 */
13
class LegacyEntityDeserializer implements Deserializer {
14
15
	/**
16
	 * @var Deserializer
17
	 */
18
	private $itemDeserializer;
19
20
	/**
21
	 * @var Deserializer
22
	 */
23
	private $propertyDeserializer;
24
25
	public function __construct( Deserializer $itemDeserializer, Deserializer $propertyDeserializer ) {
26
		$this->itemDeserializer = $itemDeserializer;
27
		$this->propertyDeserializer = $propertyDeserializer;
28
	}
29
30
	/**
31
	 * @param mixed $serialization
32
	 *
33
	 * @return EntityDocument
34
	 * @throws DeserializationException
35
	 */
36
	public function deserialize( $serialization ) {
37
		if ( !is_array( $serialization ) ) {
38
			throw new DeserializationException( 'Entity serialization must be an array' );
39
		}
40
41
		if ( $this->isPropertySerialization( $serialization ) ) {
42
			return $this->propertyDeserializer->deserialize( $serialization );
43
		}
44
45
		return $this->itemDeserializer->deserialize( $serialization );
46
	}
47
48
	private function isPropertySerialization( $serialization ) {
49
		return array_key_exists( 'datatype', $serialization );
50
	}
51
52
}
53