StatementDeserializer   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 78.56%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 53
ccs 11
cts 14
cp 0.7856
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A deserialize() 0 11 3
A isDeserializerFor() 0 4 2
1
<?php
2
3
namespace Wikibase\InternalSerialization\Deserializers;
4
5
use Deserializers\DispatchableDeserializer;
6
use Deserializers\Exceptions\DeserializationException;
7
use Wikibase\DataModel\Statement\Statement;
8
9
/**
10
 * @license GPL-2.0-or-later
11
 * @author Jeroen De Dauw < [email protected] >
12
 * @author Thiemo Kreuz
13
 */
14
class StatementDeserializer implements DispatchableDeserializer {
15
16
	/**
17
	 * @var DispatchableDeserializer
18
	 */
19
	private $legacyDeserializer;
20
21
	/**
22
	 * @var DispatchableDeserializer
23
	 */
24
	private $currentDeserializer;
25
26 5
	public function __construct(
27
		DispatchableDeserializer $legacyDeserializer,
28
		DispatchableDeserializer $currentDeserializer
29
	) {
30 5
		$this->legacyDeserializer = $legacyDeserializer;
31 5
		$this->currentDeserializer = $currentDeserializer;
32 5
	}
33
34
	/**
35
	 * @param array $serialization
36
	 *
37
	 * @return Statement
38
	 * @throws DeserializationException
39
	 */
40 5
	public function deserialize( $serialization ) {
41 5
		if ( $this->currentDeserializer->isDeserializerFor( $serialization ) ) {
42 1
			return $this->currentDeserializer->deserialize( $serialization );
43 4
		} elseif ( $this->legacyDeserializer->isDeserializerFor( $serialization ) ) {
44 2
			return $this->legacyDeserializer->deserialize( $serialization );
45
		}
46
47 2
		throw new DeserializationException(
48 2
			'The provided claim serialization is neither legacy nor current'
49
		);
50
	}
51
52
	/**
53
	 * @see DispatchableDeserializer::isDeserializerFor
54
	 *
55
	 * @since 2.2
56
	 *
57
	 * @param mixed $serialization
58
	 *
59
	 * @return bool
60
	 */
61
	public function isDeserializerFor( $serialization ) {
62
		return $this->currentDeserializer->isDeserializerFor( $serialization )
63
			|| $this->legacyDeserializer->isDeserializerFor( $serialization );
64
	}
65
66
}
67