Completed
Push — master ( 81538e...c2bf57 )
by Jeroen De
10:06
created

SubObject::getValues()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace Maps\GeoJsonPages\Semantic;
6
7
use SMW\DataModel\ContainerSemanticData;
8
use SMW\DIProperty;
9
use SMW\DIWikiPage;
10
use TitleValue;
11
12
class SubObject {
13
14
	private $name;
15
	private $values = [];
16
17
	public function __construct( string $name ) {
18
		$this->name = $name;
19
	}
20
21
	public function addPropertyValuePair( string $propertyName, \SMWDataItem $dataItem ) {
22
		$this->values[$propertyName][] = $dataItem;
23
	}
24
25
	public function toContainerSemanticData( TitleValue $subjectPage ): ContainerSemanticData {
26
		$container = $this->newContainerSemanticData( $subjectPage );
27
28
		foreach ( $this->values as $propertyName => $dataItems ) {
29
			foreach ( $dataItems as $dataItem ) {
30
				$container->addPropertyObjectValue(
31
					new DIProperty( $propertyName ),
32
					$dataItem
33
				);
34
			}
35
		}
36
37
		return $container;
38
	}
39
40
	private function newContainerSemanticData( TitleValue $subjectPage ): ContainerSemanticData {
41
		return new ContainerSemanticData(
42
			new DIWikiPage(
43
				$subjectPage->getDBkey(),
44
				$subjectPage->getNamespace(),
45
				$subjectPage->getInterwiki(),
46
				$this->name
47
			)
48
		);
49
	}
50
51
	public function getName(): string {
52
		return $this->name;
53
	}
54
55
	public function getValues(): array {
56
		return $this->values;
57
	}
58
59
}
60