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

SemanticGeoJsonStore::storeGeoJson()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2.108

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 7
cts 10
cp 0.7
rs 9.7666
c 0
b 0
f 0
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\DIProperty;
9
use SMW\ParserData;
10
use SMWDIContainer;
11
use Title;
12
13
class SemanticGeoJsonStore implements GeoJsonStore {
14
15
	private $parserData;
16
	private $subjectPage;
17
	private $smwEventDispatcher;
18
	private $subObjectBuilder;
19
20 3
	public function __construct( ParserData $parserData, Title $subjectPage, EventDispatcher $smwEventDispatcher, SubObjectBuilder $subObjectBuilder ) {
21 3
		$this->parserData = $parserData;
22 3
		$this->subjectPage = $subjectPage;
23 3
		$this->smwEventDispatcher = $smwEventDispatcher;
24 3
		$this->subObjectBuilder = $subObjectBuilder;
25 3
	}
26
27 3
	public function storeGeoJson( string $geoJson ) {
28 3
		foreach ( $this->subObjectBuilder->getSubObjectsFromGeoJson( $geoJson ) as $subObject ) {
29
			$this->parserData->getSemanticData()->addPropertyObjectValue(
30
				new DIProperty( DIProperty::TYPE_SUBOBJECT ),
31
				new SMWDIContainer( $subObject->toContainerSemanticData( $this->subjectPage->getTitleValue() ) )
32
			);
33
		}
34
35 3
		$this->parserData->copyToParserOutput();
36
37 3
		$this->smwEventDispatcher->dispatch(
38 3
			'InvalidateEntityCache',
39 3
			[ 'title' => $this->subjectPage, 'context' => 'GeoJsonContent' ]
40
		);
41 3
	}
42
43
}
44