Completed
Pull Request — master (#13)
by Jeroen De
03:37
created

SimpleSlidePresenter   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 30
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getText() 0 3 1
A getDisplayValues() 0 7 3
A getDisplayValue() 0 10 2
A dataItemToText() 0 3 1
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace ModernTimeline\SlidePresenter;
6
7
use ModernTimeline\ResultFacade\Subject;
8
use SMW\DataValueFactory;
9
use SMW\Query\PrintRequest;
10
11
class SimpleSlidePresenter implements SlidePresenter {
12
13 2
	public function getText( Subject $subject ): string {
14 2
		return implode( '<br>', iterator_to_array( $this->getDisplayValues( $subject ) ) );
15
	}
16
17 2
	private function getDisplayValues( Subject $subject ) {
18 2
		foreach ( $subject->getPropertyValueCollections() as $propertyValues ) {
19 2
			foreach ( $propertyValues->getDataItems() as $dataItem ) {
20 2
				yield $this->getDisplayValue( $propertyValues->getPrintRequest(), $dataItem );
21
			}
22
		}
23 2
	}
24
25 2
	private function getDisplayValue( PrintRequest $pr, \SMWDataItem $dataItem ) {
26 2
		$property = $pr->getText( null );
27 2
		$value = $this->dataItemToText( $dataItem );
28
29 2
		if ( $property === '' ) {
30 2
			return $value;
31
		}
32
33 2
		return $property . ': ' . $value;
34
	}
35
36 2
	private function dataItemToText( \SMWDataItem $dataItem ): string {
37 2
		return DataValueFactory::getInstance()->newDataValueByItem( $dataItem )->getLongHTMLText();
38
	}
39
40
}
41