DeserializerFactory::newClaimDeserializer()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Wikibase\InternalSerialization;
4
5
use Deserializers\Deserializer;
6
use Deserializers\DispatchableDeserializer;
7
use Wikibase\DataModel\DeserializerFactory as CurrentDeserializerFactory;
8
use Wikibase\DataModel\Entity\EntityIdParser;
9
use Wikibase\InternalSerialization\Deserializers\EntityDeserializer;
10
use Wikibase\InternalSerialization\Deserializers\StatementDeserializer;
11
12
/**
13
 * Public interface of the library for constructing deserializers.
14
 * Direct access to deserializers is prohibited, users are only allowed to
15
 * know about this interface. Also note that the return type of the methods
16
 * is "Deserializer". You are also not allowed to know which concrete
17
 * implementation is returned.
18
 *
19
 * The returned deserializers can handle both serializations in the
20
 * legacy internal format and in the new one.
21
 *
22
 * @since 1.0
23
 *
24
 * @license GPL-2.0-or-later
25
 * @author Jeroen De Dauw < [email protected] >
26
 */
27
class DeserializerFactory {
28
29
	/**
30
	 * @var LegacyDeserializerFactory
31
	 */
32
	private $legacyFactory;
33
34
	/**
35
	 * @var CurrentDeserializerFactory
36
	 */
37
	private $currentFactory;
38
39
	/**
40
	 * @var DispatchableDeserializer|null
41
	 */
42
	private $currentEntityDeserializer;
43
44
	/**
45
	 * @param Deserializer $dataValueDeserializer
46
	 * @param EntityIdParser $idParser
47
	 * @param DispatchableDeserializer|null $currentEntityDeserializer used instead of constructing
48
	 *        a new current Deserializer for entities using a current DeserializerFactory.
49
	 */
50 18
	public function __construct(
51
		Deserializer $dataValueDeserializer,
52
		EntityIdParser $idParser,
53
		DispatchableDeserializer $currentEntityDeserializer = null
54
	) {
55 18
		$this->legacyFactory = new LegacyDeserializerFactory( $dataValueDeserializer, $idParser );
56 18
		$this->currentFactory = new CurrentDeserializerFactory( $dataValueDeserializer, $idParser );
57 18
		$this->currentEntityDeserializer = $currentEntityDeserializer;
58 18
	}
59
60
	/**
61
	 * @return Deserializer
62
	 */
63 17
	public function newEntityDeserializer() {
64 17
		return new EntityDeserializer(
65 17
			$this->legacyFactory->newEntityDeserializer(),
66 17
			$this->currentEntityDeserializer ?: $this->currentFactory->newEntityDeserializer()
67
		);
68
	}
69
70
	/**
71
	 * @since 1.1
72
	 * @deprecated since 1.4 - use newStatementDeserializer instead
73
	 *
74
	 * @return Deserializer
75
	 */
76
	public function newClaimDeserializer() {
77
		return $this->newStatementDeserializer();
78
	}
79
80
	/**
81
	 * @since 1.4
82
	 *
83
	 * @return Deserializer
84
	 */
85 1
	public function newStatementDeserializer() {
86 1
		return new StatementDeserializer(
87 1
			$this->legacyFactory->newStatementDeserializer(),
88 1
			$this->currentFactory->newStatementDeserializer()
89
		);
90
	}
91
92
}
93