Completed
Pull Request — master (#603)
by Jeroen De
01:20
created

SubObject::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace Maps\DataAccess\GeoJsonStore;
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 2
	public function __construct( string $name ) {
18 2
		$this->name = $name;
19 2
	}
20
21 1
	public function addPropertyValuePair( string $propertyName, \SMWDataItem $dataItem ) {
22 1
		$this->values[$propertyName][] = $dataItem;
23 1
	}
24
25 2
	public function toContainerSemanticData( TitleValue $subjectPage ): ContainerSemanticData {
26 2
		$container = $this->newContainerSemanticData( $subjectPage );
27
28 2
		foreach ( $this->values as $propertyName => $dataItems ) {
29 1
			foreach ( $dataItems as $dataItem ) {
30 1
				$container->addPropertyObjectValue(
31 1
					new DIProperty( $propertyName ),
32
					$dataItem
33
				);
34
			}
35
		}
36
37 2
		return $container;
38
	}
39
40 2
	private function newContainerSemanticData( TitleValue $subjectPage ): ContainerSemanticData {
41 2
		return new ContainerSemanticData(
42 2
			new DIWikiPage(
43 2
				$subjectPage->getDBkey(),
44 2
				$subjectPage->getNamespace(),
45 2
				$subjectPage->getInterwiki(),
46 2
				$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