InMemoryEntityTermStore   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 37
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setTerms() 0 3 1
A unsetTerms() 0 3 1
A hasExactTerms() 0 7 2
A hasNoTerms() 0 3 1
1
<?php
2
3
namespace Wikibase\TermStore\MediaWiki\PackagePrivate;
4
5
use Wikibase\DataModel\Entity\EntityId;
6
7
/**
8
 * in-memory, @inheritDoc
9
 */
10
class InMemoryEntityTermStore implements EntityTermStore {
11
	private $entityTerms = [];
12
13
	public function setTerms( EntityId $entityId, array $termsArray ) {
14
		$this->entityTerms[$entityId->getSerialization()] = $termsArray;
15
	}
16
17
	public function unsetTerms( EntityId $entityId ) {
18
		unset( $this->entityTerms[$entityId->getSerialization()] );
19
	}
20
21
	/**
22
	 * check that terms for the given entity id has the given terms stored
23
	 *
24
	 * @param EntityId $entityId
25
	 * @param array $termsArray same as $termsArray for InMemoryEntityTermStore::setTerms()
26
	 *
27
	 * @return bool
28
	 */
29
	public function hasExactTerms( EntityId $entityId, array $termsArray ) {
30
		if ( !isset( $this->entityTerms[$entityId->getSerialization()] ) ) {
31
			return false;
32
		}
33
34
		return $termsArray === $this->entityTerms[$entityId->getSerialization()];
35
	}
36
37
	/**
38
	 * Check that given entity id has no terms stored
39
	 *
40
	 * @return bool
41
	 */
42
	public function hasNoTerms( EntityId $entityId ) {
43
		return !isset( $this->entityTerms[$entityId->getSerialization()] );
44
	}
45
46
}
47