QueryResult   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 96.55%

Importance

Changes 0
Metric Value
wmc 10
lcom 2
cbo 3
dl 0
loc 97
ccs 28
cts 29
cp 0.9655
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setRemoteTargetUrl() 0 3 1
A setJsonResponseParser() 0 3 1
A toArray() 0 3 1
A serializeToArray() 0 3 1
A getNext() 0 16 3
A getLink() 0 16 3
1
<?php
2
3
namespace SEQL\ByHttpRequest;
4
5
use SMWInfolink as Infolink;
6
use SMWQueryResult as RootQueryResult;
7
8
/**
9
 * @license GNU GPL v2+
10
 * @since 1.0
11
 *
12
 * @author mwjames
13
 */
14
class QueryResult extends RootQueryResult {
15
16
	/**
17
	 * @var string
18
	 */
19
	private $remoteTargetUrl = '';
20
21
	/**
22
	 * @var JsonResponseParser
23
	 */
24
	private $jsonResponseParser;
25
26
	/**
27
	 * @since 1.0
28
	 *
29
	 * @param string $remoteTargetUrl
30
	 */
31 1
	public function setRemoteTargetUrl( $remoteTargetUrl ) {
32 1
		$this->remoteTargetUrl = $remoteTargetUrl;
33 1
	}
34
35
	/**
36
	 * @since 1.0
37
	 *
38
	 * @param JsonResponseParser $jsonResponseParser
39
	 */
40 2
	public function setJsonResponseParser( JsonResponseParser $jsonResponseParser ) {
41 2
		$this->jsonResponseParser = $jsonResponseParser;
42 2
	}
43
44
	/**
45
	 * @see QueryResult::toArray
46
	 *
47
	 * @since 1.0
48
	 *
49
	 * @return array
50
	 */
51 1
	public function toArray() {
52 1
		return $this->jsonResponseParser->getRawResponseResult();
53
	}
54
55
	/**
56
	 * @see QueryResult::serializeToArray
57
	 *
58
	 * @since 1.0
59
	 *
60
	 * @return array
61
	 */
62 1
	public function serializeToArray() {
63 1
		return $this->toArray();
64
	}
65
66
	/**
67
	 * @since 1.0
68
	 *
69
	 * @return CannedResultArray[]|false
70
	 */
71 1
	public function getNext() {
72 1
		$page = current( $this->mResults );
73 1
		next( $this->mResults );
74
75 1
		if ( $page === false ) {
76
			return false;
77
		}
78
79 1
		$row = array();
80
81 1
		foreach ( $this->mPrintRequests as $p ) {
82 1
			$row[] = new CannedResultArray( $page, $p, $this->jsonResponseParser );
83 1
		}
84
85 1
		return $row;
86
	}
87
88
	/**
89
	 * @since 1.0
90
	 *
91
	 * @return SMWInfolink
92
	 */
93 1
	public function getLink() {
94 1
		$params = array( trim( $this->getQuery()->getQueryString() ) );
95
96 1
		foreach ( $this->getQuery()->getExtraPrintouts() as $printout ) {
97 1
			$serialization = $printout->getSerialisation();
98
99
			// TODO: this is a hack to get rid of the mainlabel param in case it was automatically added
100
			// by SMWQueryProcessor::addThisPrintout. Should be done nicer when this link creation gets redone.
101 1
			if ( $serialization !== '?#' ) {
102 1
				$params[] = $serialization;
103 1
			}
104 1
		}
105
106
		// Note: the initial : prevents SMW from reparsing :: in the query string.
107 1
		return Infolink::newExternalLink( '', $this->remoteTargetUrl . 'Special:Ask', false, $params );
108
	}
109
110
}
111