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

SimpleSlidePresenter::getDisplayValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

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