Berlin::newSiteLinkList()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Wikibase\DataFixtures\Items;
4
5
use DataValues\StringValue;
6
use Wikibase\DataFixtures\Properties\CountryProperty;
7
use Wikibase\DataFixtures\Properties\InstanceOfProperty;
8
use Wikibase\DataFixtures\Properties\PostalCodeProperty;
9
use Wikibase\DataModel\Entity\EntityIdValue;
10
use Wikibase\DataModel\Entity\Item;
11
use Wikibase\DataModel\Entity\ItemId;
12
use Wikibase\DataModel\Entity\Property;
13
use Wikibase\DataModel\SiteLinkList;
14
use Wikibase\DataModel\Snak\PropertyValueSnak;
15
use Wikibase\DataModel\Statement\StatementList;
16
use Wikibase\DataModel\Term\Fingerprint;
17
18
/**
19
 * @licence GNU GPL v2+
20
 * @author Jeroen De Dauw < [email protected] >
21
 */
22
class Berlin {
23
24
	/**
25
	 * @var Germany
26
	 */
27
	private $germany;
28
29
	/**
30
	 * @var City
31
	 */
32
	private $city;
33
34
	/**
35
	 * @var CountryProperty
36
	 */
37
	private $country;
38
39
	/**
40
	 * @var InstanceOfProperty
41
	 */
42
	private $instanceOf;
43
44
	/**
45
	 * @var PostalCodeProperty
46
	 */
47
	private $postCode;
48
49 1
	public function __construct() {
50 1
		$this->germany = new Germany();
51 1
		$this->city = new City();
52
53 1
		$this->country = new CountryProperty();
54 1
		$this->instanceOf = new InstanceOfProperty();
55 1
		$this->postCode = new PostalCodeProperty();
56 1
	}
57
58 1
	public function newItem() {
59 1
		$item = new Item( new ItemId( 'Q64' ) );
60
61 1
		$item->setFingerprint( $this->newFingerprint() );
62 1
		$item->setStatements( $this->newStatements() );
63 1
		$item->setSiteLinkList( $this->newSiteLinkList() );
64
65 1
		return $item;
66
	}
67
68 1
	public function newFingerprint() {
69 1
		$fingerprint = new Fingerprint();
70
71 1
		$fingerprint->setLabel( 'en', 'Berlin' );
72 1
		$fingerprint->setLabel( 'de', 'Berlin' );
73 1
		$fingerprint->setLabel( 'nl', 'Berlijn' );
74
75 1
		$fingerprint->setDescription( 'en', 'capital city and state of Germany' );
76 1
		$fingerprint->setDescription( 'de', 'Hauptstadt von Deutschland' );
77
78 1
		return $fingerprint;
79
	}
80
81 1
	public function newSiteLinkList() {
82 1
		$links = new SiteLinkList();
83
84 1
		$links->addNewSiteLink( 'enwiki', 'Berlin' );
85 1
		$links->addNewSiteLink( 'nlwiki', 'Berlijn' );
86
87 1
		return $links;
88
	}
89
90 1
	public function newStatements() {
91 1
		$statements = new StatementList();
92
93 1
		$statements->addNewStatement(
94 1
			new PropertyValueSnak(
95 1
				$this->country->newPropertyId(),
96 1
				new EntityIdValue( $this->germany->newItemId() )
97 1
			),
98 1
			null,
99 1
			null,
100
			'first guid'
101 1
		);
102
103 1
		$statements->addNewStatement(
104 1
			new PropertyValueSnak(
105 1
				$this->instanceOf->newPropertyId(),
106 1
				new EntityIdValue( $this->city->newItemId() )
107 1
			),
108 1
			null,
109 1
			null,
110
			'second guid'
111 1
		);
112
113 1
		$statements->addNewStatement(
114 1
			new PropertyValueSnak(
115 1
				$this->postCode->newPropertyId(),
116 1
				new StringValue( '10115–14199' )
117 1
			),
118 1
			null,
119 1
			null,
120
			'third guid'
121 1
		);
122
123 1
		return $statements;
124
	}
125
126
	/**
127
	 * @return Item[]
128
	 */
129
	public function getItemDependencies() {
130
		return [
131
			$this->germany->newItem(),
132
			$this->city->newItem()
133
		];
134
	}
135
136
	/**
137
	 * @return Property[]
138
	 */
139
	public function getPropertyDependencies() {
140
		return [
141
			$this->country->newProperty(),
142
			$this->instanceOf->newProperty()
143
		];
144
	}
145
146
}
147