SimplePropertyBuilder::addDescription()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 5
ccs 5
cts 5
cp 1
crap 2
rs 10
c 0
b 0
f 0
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