ReferencedEntitiesFinder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 0
loc 24
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A findForItem() 0 15 4
1
<?php
2
3
namespace Queryr\Replicator\EntitySource;
4
5
use Wikibase\DataModel\Entity\EntityId;
6
use Wikibase\DataModel\Entity\EntityIdValue;
7
use Wikibase\DataModel\Entity\Item;
8
use Wikibase\DataModel\Snak\PropertyValueSnak;
9
10
/**
11
 * @licence GNU GPL v2+
12
 * @author Jeroen De Dauw < [email protected] >
13
 */
14
class ReferencedEntitiesFinder {
15
16
	/**
17
	 * @param Item $item
18
	 *
19
	 * @return EntityId[]
20
	 */
21 3
	public function findForItem( Item $item ): array {
22 3
		$references = [];
23
24 3
		foreach ( $item->getStatements()->toArray() as $statement ) {
25 2
			$references[] = $statement->getPropertyId();
26
27 2
			$mainSnak = $statement->getMainSnak();
28
29 2
			if ( $mainSnak instanceof PropertyValueSnak && $mainSnak->getDataValue() instanceof EntityIdValue ) {
30 2
				$references[] = $mainSnak->getDataValue()->getEntityId();
31
			}
32
		}
33
34 3
		return array_unique( $references );
35
	}
36
37
}