Completed
Push — master ( 9b2ed5...981814 )
by Jeroen De
76:07
created

ResultItem   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 6
dl 0
loc 90
ccs 40
cts 45
cp 0.8889
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setData() 0 7 2
A unsetData() 0 3 1
A getData() 0 3 1
A getValue() 0 3 1
B getArrayRepresentation() 0 51 6
1
<?php
2
3
namespace SRF\Filtered;
4
5
use SMWDataValue;
6
use SMWDIGeoCoord;
7
use SMWDIWikiPage;
8
use SMWErrorValue;
9
use SMWResultArray;
10
11
/**
12
 * File holding the SRF_Filtered_Item class
13
 *
14
 * @author Stephan Gambke
15
 * @file
16
 * @ingroup SemanticResultFormats
17
 */
18
19
/**
20
 * The SRF_Filtered_Item class.
21
 *
22
 * @ingroup SemanticResultFormats
23
 */
24
class ResultItem {
25
26
	private $mResultArray;
27
	private $mItemData = [];
28
	private $mQueryPrinter;
29
30
	/**
31
	 * @param SMWResultArray[] $resultArray
32
	 * @param Filtered $queryPrinter
33
	 */
34 2
	public function __construct( array $resultArray, Filtered &$queryPrinter ) {
35 2
		$this->mResultArray = $resultArray;
36 2
		$this->mQueryPrinter = $queryPrinter;
37 2
	}
38
39 1
	public function setData( $viewOrFilterId, $data ) {
40 1
		if ( $data === null ) {
41 1
			$this->unsetData( $viewOrFilterId );
42
		} else {
43 1
			$this->mItemData[$viewOrFilterId] = $data;
44
		}
45 1
	}
46
47 1
	public function unsetData( $viewOrFilterId ) {
48 1
		unset( $this->mItemData[$viewOrFilterId] );
49 1
	}
50
51
	public function getData( $viewOrFilterId ) {
52
		return $this->mItemData[$viewOrFilterId];
53
	}
54
55
	/**
56
	 * @return SMWResultArray[]
57
	 */
58 1
	public function getValue() {
59 1
		return $this->mResultArray;
60
	}
61
62 2
	public function getArrayRepresentation() {
63
64 2
		$printouts = [];
65 2
		$isFirstColumn = true;
66
67 2
		foreach ( $this->mResultArray as $field ) {
68
69 2
			$printRequest = $field->getPrintRequest();
70
71 2
			$values = []; // contains plain text
72 2
			$formatted = []; // may contain links
73 2
			$sorted = []; // uses DEFAULTSORT when available
74
75 2
			$field->reset();
76
77 2
			while ( ( $dataValue = $field->getNextDataValue() ) instanceof SMWDataValue ) {
78
79 2
				$dataItem = $dataValue->getDataItem();
80
81 2
				if ( $dataItem instanceof SMWDIGeoCoord ) {
82
					$values[] = [ 'lat' => $dataItem->getLatitude(), 'lng' => $dataItem->getLongitude() ];
83
					$sorted[] = $dataItem->getSortKey();
84 2
				} elseif ( $dataItem instanceof SMWDIWikiPage ) {
85 2
					$values[] = $dataValue->getShortWikiText();
86 2
					$sorted[] = $dataValue->getSortKey();
87
				} else {
88 2
					$values[] = $dataValue->getShortWikiText();
89 2
					$sorted[] = $dataValue->getShortWikiText();
90
				}
91
92 2
				if ( $dataValue instanceof SMWErrorValue ) {
93
					$formatted[] = $dataItem->getSerialization();
94
				} else {
95 2
					$formatted[] = $dataValue->getShortHTMLText( $this->mQueryPrinter->getLinker( $isFirstColumn ) );
96
				}
97
			}
98
99 2
			$printouts[$this->mQueryPrinter->uniqid( $printRequest->getHash() )] = [
0 ignored issues
show
Bug introduced by
It seems like $printRequest->getHash() targeting SMW\Query\PrintRequest::getHash() can also be of type boolean; however, SRF\Filtered\Filtered::uniqid() does only seem to accept string|null, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
100 2
				'values' => $values,
101 2
				'formatted values' => $formatted,
102 2
				'sort values' => $sorted,
103
			];
104
105 2
			$isFirstColumn = false;
106
		}
107
108
		return [
109 2
			'printouts' => $printouts,
110 2
			'data' => $this->mItemData,
111
		];
112
	}
113
}
114