SimplePropertyBuilder   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 3
dl 0
loc 62
ccs 33
cts 33
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A buildFromProperty() 0 14 1
A addIdLinks() 0 3 1
A addLabel() 0 5 2
A addDescription() 0 5 2
A addAliases() 0 5 2
A addType() 0 3 1
1
<?php
2
3
namespace Queryr\Resources\Builders;
4
5
use Queryr\Resources\SimpleProperty;
6
use Wikibase\DataModel\Entity\Property;
7
8
/**
9
 * @licence GNU GPL v2+
10
 * @author Jeroen De Dauw < [email protected] >
11
 */
12
class SimplePropertyBuilder {
13
14
	const MAIN_LANGUAGE = 'en';
15
16
	private $languageCode;
17
18
	/**
19
	 * @var Property
20
	 */
21
	private $property;
22
23
	/**
24
	 * @var SimpleProperty
25
	 */
26
	private $simpleProperty;
27
28 3
	public function __construct( $languageCode ) {
29 3
		$this->languageCode = $languageCode;
30 3
	}
31
32 3
	public function buildFromProperty( Property $property ) {
33 3
		$this->property = $property;
34 3
		$this->simpleProperty = new SimpleProperty();
35
36 3
		$this->addIdLinks();
37
38 3
		$this->addLabel();
39 3
		$this->addDescription();
40 3
		$this->addAliases();
41
42 3
		$this->addType();
43
44 3
		return $this->simpleProperty;
45
	}
46
47 3
	private function addIdLinks() {
48 3
		$this->simpleProperty->ids['wikidata'] = $this->property->getId()->getSerialization();
49 3
	}
50
51 3
	private function addLabel() {
52 3
		if ( $this->property->getFingerprint()->getLabels()->hasTermForLanguage( $this->languageCode ) ) {
53 3
			$this->simpleProperty->label = $this->property->getFingerprint()->getLabel( $this->languageCode )->getText();
54 3
		}
55 3
	}
56
57 3
	private function addDescription() {
58 3
		if ( $this->property->getFingerprint()->getDescriptions()->hasTermForLanguage( $this->languageCode ) ) {
59 1
			$this->simpleProperty->description = $this->property->getFingerprint()->getDescription( $this->languageCode )->getText();
60 1
		}
61 3
	}
62
63 3
	private function addAliases() {
64 3
		if ( $this->property->getFingerprint()->getAliasGroups()->hasGroupForLanguage( $this->languageCode ) ) {
65 2
			$this->simpleProperty->aliases = $this->property->getFingerprint()->getAliasGroup( $this->languageCode )->getAliases();
66 2
		}
67 3
	}
68
69 3
	private function addType() {
70 3
		$this->simpleProperty->type = $this->property->getDataTypeId();
71 3
	}
72
73
}
74