Completed
Push — master ( dc1683...3e9aec )
by mw
07:38 queued 05:33
created

CompoundQuery   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 3
dl 0
loc 83
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 14 2
A getAllowedParams() 0 8 1
A getParamDescription() 0 5 1
A getDescription() 0 5 1
A getExamples() 0 6 1
A getVersion() 0 3 1
1
<?php
2
3
namespace SCQ\Api;
4
5
use SMW\MediaWiki\Api\Query;
6
use SMW\MediaWiki\Api\ApiRequestParameterFormatter;
7
use SCQ\CompoundQueryProcessor;
8
use ApiBase;
9
10
/**
11
 * API module to query SMW by providing multiple queries in the ask language.
12
 *
13
 * @license GNU GPL v2+
14
 * @since 1.0
15
 *
16
 * @author Peter Grassberger < [email protected] >
17
 */
18
class CompoundQuery extends Query {
19
20
	/**
21
	 * @see ApiBase::execute
22
	 */
23
	public function execute() {
24
		$parameterFormatter = new ApiRequestParameterFormatter( $this->extractRequestParams() );
25
		$parameters = $parameterFormatter->getAskApiParameters();
26
27
		list( $queryParams, $otherParams ) = CompoundQueryProcessor::separateParams( $parameters );
28
		list( $queryResult ) = CompoundQueryProcessor::queryAndMergeResults( $queryParams, $otherParams );
29
30
		$outputFormat = 'json';
31
		if ( $this->getMain()->getPrinter() instanceof \ApiFormatXml ) {
0 ignored issues
show
Bug introduced by
The class ApiFormatXml does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
32
			$outputFormat = 'xml';
33
		}
34
35
		$this->addQueryResult( $queryResult, $outputFormat );
36
	}
37
38
	/**
39
	 * @codeCoverageIgnore
40
	 * @see ApiBase::getAllowedParams
41
	 *
42
	 * @return array
43
	 */
44
	public function getAllowedParams() {
45
		return array(
46
			'query' => array(
47
				ApiBase::PARAM_TYPE => 'string',
48
				ApiBase::PARAM_REQUIRED => true,
49
			),
50
		);
51
	}
52
53
	/**
54
	 * @codeCoverageIgnore
55
	 * @see ApiBase::getParamDescription
56
	 *
57
	 * @return array
58
	 */
59
	public function getParamDescription() {
60
		return array(
61
			'query' => 'The multiple queries string in ask-language'
62
		);
63
	}
64
65
	/**
66
	 * @codeCoverageIgnore
67
	 * @see ApiBase::getDescription
68
	 *
69
	 * @return array
70
	 */
71
	public function getDescription() {
72
		return array(
73
			'API module to query SMW by providing a multiple queries in the ask language.'
74
		);
75
	}
76
77
	/**
78
	 * @codeCoverageIgnore
79
	 * @see ApiBase::getExamples
80
	 *
81
	 * @return array
82
	 */
83
	protected function getExamples() {
84
		return array(
85
			'api.php?action=compoundquery&query=' . urlencode( '[[Has city::Vienna]]; ?Has coordinates|[[Has city::Graz]]; ?Has coordinates' ),
86
			'api.php?action=compoundquery&query=' . urlencode( '|[[Has city::Vienna]]; ?Has coordinates|[[Has city::Graz]]; ?Has coordinates' ),
87
		);
88
	}
89
90
	/**
91
	 * @codeCoverageIgnore
92
	 * @see ApiBase::getVersion
93
	 *
94
	 * @return string
95
	 */
96
	public function getVersion() {
97
		return __CLASS__ . '-' . SCQ_VERSION;
98
	}
99
100
}
101