Completed
Push — master ( 952e89...59c62b )
by Jeroen De
03:27
created

SimpleSlidePresenter::getDisplayValues()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 12
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
	public function getText( Subject $subject ): string {
14
		return implode( '<br>', iterator_to_array( $this->getDisplayValues( $subject ) ) );
15
	}
16
17
	private function getDisplayValues( Subject $subject ) {
18
		foreach ( $subject->getPropertyValueCollections() as $propertyValues ) {
19
			foreach ( $propertyValues->getDataItems() as $dataItem ) {
20
				yield $this->getDisplayValue( $propertyValues->getPrintRequest(), $dataItem );
21
			}
22
		}
23
	}
24
25
	private function getDisplayValue( PrintRequest $pr, \SMWDataItem $dataItem ) {
26
		$property = $pr->getText( null );
27
		$value = $this->dataItemToText( $dataItem );
28
29
		if ( $property === '' ) {
30
			return $value;
31
		}
32
33
		return $property . ': ' . $value;
34
	}
35
36
	private function dataItemToText( \SMWDataItem $dataItem ): string {
37
		return DataValueFactory::getInstance()->newDataValueByItem( $dataItem )->getLongHTMLText();
38
	}
39
40
}
41