Completed
Push — SemanticGeoJson ( e5361a...e30e84 )
by Jeroen De
03:54
created

SemanticGeoJsonStore   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 81.25%

Importance

Changes 0
Metric Value
dl 0
loc 36
c 0
b 0
f 0
wmc 3
lcom 1
cbo 2
ccs 13
cts 16
cp 0.8125
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A storeGeoJson() 0 20 2
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace Maps\DataAccess\GeoJsonStore;
6
7
use Onoi\EventDispatcher\EventDispatcher;
8
use SMW\DataModel\ContainerSemanticData;
9
use SMW\DIProperty;
10
use SMW\DIWikiPage;
11
use SMW\ParserData;
12
use SMWDIContainer;
13
use Title;
14
15
class SemanticGeoJsonStore implements GeoJsonStore {
16
17
	private $parserData;
18
	private $subjectPage;
19
	private $smwEventDispatcher;
20
	private $subObjectBuilder;
21
22 3
	public function __construct( ParserData $parserData, Title $subjectPage, EventDispatcher $smwEventDispatcher, SubObjectBuilder $subObjectBuilder ) {
23 3
		$this->parserData = $parserData;
24 3
		$this->subjectPage = $subjectPage;
25 3
		$this->smwEventDispatcher = $smwEventDispatcher;
26 3
		$this->subObjectBuilder = $subObjectBuilder;
27 3
	}
28
29 3
	public function storeGeoJson( string $geoJson ) {
30
//		$this->parserData->getSemanticData()->addPropertyObjectValue(
31
//			new DIProperty( 'HasNumber' ),
32
//			new \SMWDINumber( 44 )
33
//		);
34
35 3
		foreach ( $this->subObjectBuilder->getSubObjectsFromGeoJson( $geoJson ) as $subObject ) {
36
			$this->parserData->getSemanticData()->addPropertyObjectValue(
37
				new DIProperty( DIProperty::TYPE_SUBOBJECT ),
38
				new SMWDIContainer( $subObject->toContainerSemanticData( $this->subjectPage->getTitleValue() ) )
39
			);
40
		}
41
42 3
		$this->parserData->copyToParserOutput();
43
44 3
		$this->smwEventDispatcher->dispatch(
45 3
			'InvalidateEntityCache',
46 3
			[ 'title' => $this->subjectPage, 'context' => 'GeoJsonContent' ]
47
		);
48 3
	}
49
50
}
51