Completed
Push — master ( 36e04f...8ec39e )
by Jeroen De
04:55 queued 03:58
created

SimpleSlidePresenter   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 95.24%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 1
dl 0
loc 42
ccs 20
cts 21
cp 0.9524
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getText() 0 3 1
A getDisplayValues() 0 9 4
A __construct() 0 3 1
A isHiddenPrintRequest() 0 3 1
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
	private $parameters;
14
15 3
	public function __construct( array $parameters ) {
16 3
		$this->parameters = $parameters;
17 3
	}
18
19 2
	public function getText( Subject $subject ): string {
20 2
		return implode( '<br>', iterator_to_array( $this->getDisplayValues( $subject ) ) );
21
	}
22
23 2
	private function getDisplayValues( Subject $subject ) {
24 2
		foreach ( $subject->getPropertyValueCollections() as $propertyValues ) {
25 2
			foreach ( $propertyValues->getDataItems() as $dataItem ) {
26 2
				if ( !$this->isHiddenPrintRequest( $propertyValues->getPrintRequest() ) ) {
27 2
					yield $this->getDisplayValue( $propertyValues->getPrintRequest(), $dataItem );
28
				}
29
			}
30
		}
31 2
	}
32
33 2
	private function isHiddenPrintRequest( PrintRequest $pr ) {
34 2
		return $pr->getText( null ) === $this->parameters['image property'];
35
	}
36
37 2
	private function getDisplayValue( PrintRequest $pr, \SMWDataItem $dataItem ) {
38 2
		$property = $pr->getText( null );
39 2
		$value = $this->dataItemToText( $dataItem );
40
41 2
		if ( $property === '' ) {
42
			return $value;
43
		}
44
45 2
		return $property . ': ' . $value;
46
	}
47
48 2
	private function dataItemToText( \SMWDataItem $dataItem ): string {
49 2
		return DataValueFactory::getInstance()->newDataValueByItem( $dataItem )->getLongHTMLText();
50
	}
51
52
}
53