SimpleSlidePresenter::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace ModernTimeline\SlidePresenter;
6
7
use ModernTimeline\ResultFacade\Subject;
8
use SMW\DataValueFactory;
0 ignored issues
show
Bug introduced by
The type SMW\DataValueFactory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use SMW\Query\PrintRequest;
0 ignored issues
show
Bug introduced by
The type SMW\Query\PrintRequest was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Traversable;
11
12
class SimpleSlidePresenter implements SlidePresenter {
13
14
	public function __construct(
15 3
		private array $parameters
16 3
	) {
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 ): Traversable {
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 ): bool {
34 2
		return $pr->getText( null ) === $this->parameters['image property'];
35
	}
36
37 2
	private function getDisplayValue( PrintRequest $pr, \SMWDataItem $dataItem ): string {
0 ignored issues
show
Bug introduced by
The type SMWDataItem was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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