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

ResultSimplifier   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 3
dl 0
loc 47
ccs 0
cts 26
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A newSubjectCollection() 0 9 2
A newSubject() 0 14 3
A newResultArray() 0 8 2
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace ModernTimeline\ResultFacade;
6
7
use SMW\DIWikiPage;
8
use SMW\Query\PrintRequest;
9
use SMWQueryResult;
10
11
class ResultSimplifier {
12
13
	public function newSubjectCollection( SMWQueryResult $result ): SubjectCollection {
14
		$subjects = [];
15
16
		foreach ( $result->getResults() as $diWikiPage ) {
17
			$subjects[] = $this->newSubject( $diWikiPage, $result->getPrintRequests(), $result );
18
		}
19
20
		return new SubjectCollection( $subjects );
21
	}
22
23
	/**
24
	 * @param DIWikiPage $resultPage
25
	 * @param PrintRequest[] $printRequests
26
	 * @param SMWQueryResult $result
27
	 * @return Subject
28
	 */
29
	private function newSubject( DIWikiPage $resultPage, array $printRequests, SMWQueryResult $result ): Subject {
30
		$propertyValueCollections = [];
31
32
		foreach ( $printRequests as $printRequest ) {
33
			$dataItems = $this->newResultArray( $resultPage, $printRequest, $result )->getContent();
34
35
			$propertyValueCollections[] = new PropertyValueCollection(
36
				$printRequest,
37
				$dataItems === false ? [] : $dataItems
38
			);
39
		}
40
41
		return new Subject( $resultPage, $propertyValueCollections );
42
	}
43
44
	/**
45
	 * Compat with SMW 3.0
46
	 * In 3.1+ do: ResultArray::factory( $resultPage, $printRequest, $result )
47
	 */
48
	private function newResultArray( DIWikiPage $resultPage, PrintRequest $printRequest, SMWQueryResult $result ): \SMWResultArray {
49
		return new \SMWResultArray(
50
			$resultPage,
51
			$printRequest,
52
			$result->getStore(),
53
			method_exists( $result, 'getFieldItemFinder' ) ? $result->getFieldItemFinder() : null
54
		);
55
	}
56
57
}
58