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

SimpleSlidePresenter::dataItemToText()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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