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

SemanticGeoJsonStore::storeGeoJson()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2.108

Importance

Changes 0
Metric Value
dl 0
loc 20
c 0
b 0
f 0
ccs 7
cts 10
cp 0.7
rs 9.6
cc 2
nc 2
nop 1
crap 2.108
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