Completed
Push — master ( 6dc7d8...407c40 )
by Karsten
15:45
created

formats/filtered/src/ResultItem.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
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