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

SubObject   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 48
ccs 20
cts 24
cp 0.8333
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A addPropertyValuePair() 0 3 1
A toContainerSemanticData() 0 14 3
A newContainerSemanticData() 0 10 1
A getName() 0 3 1
A getValues() 0 3 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