Completed
Push — master ( f280a6...cbf1b6 )
by Karsten
17:24
created

ApiSemanticFormsSelect::getParser()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 1
cp 0
rs 9.9666
c 0
b 0
f 0
cc 3
nc 3
nop 0
crap 12
1
<?php
2
3
/**
4
 * API modules to communicate with the back-end
5
 *
6
 * @license GNU GPL v2+
7
 * @since 1.2
8
 *
9
 * @author Jason Zhang
10
 * @author Toni Hermoso Pulido
11
 */
12
13
namespace SFS;
14
15
use ApiBase;
16
use Parser;
17
use ParserOptions;
18
use ParserOutput;
19
use Title;
20
21
class ApiSemanticFormsSelect extends ApiBase {
22
23
	/**
24
	 * @see ApiBase::execute
25 1
	 */
26
	public function execute() {
27 1
		$parser = $this->getParser();
28 1
		$parser->setTitle( Title::newFromText( 'NO TITLE' ) );
29 1
		$parser->mOptions = new ParserOptions();
30 1
		$parser->mOutput = new ParserOutput();
31
32 1
		$apiRequestProcessor = new \SFS\ApiSemanticFormsSelectRequestProcessor( $parser );
33 1
		$apiRequestProcessor->setDebugFlag( $GLOBALS['wgSF_Select_debug'] );
34
35 1
		$resultValues = $apiRequestProcessor->getJsonDecodedResultValuesForRequestParameters(
36 1
			$this->extractRequestParams()
37 1
		);
38
39 1
		$result = $this->getResult();
40 1
		$result->setIndexedTagName( $resultValues->values, 'value' );
41 1
		$result->addValue( $this->getModuleName(), 'values', $resultValues->values );
42 1
		$result->addValue( $this->getModuleName(), 'count', $resultValues->count );
43
44 1
		return true;
45
	}
46
47
	/**
48
	 * @see ApiBase::getAllowedParams
49
	 */
50 1
	public function getAllowedParams() {
51
		return [
52
			'approach' => [
53 1
				ApiBase::PARAM_TYPE => 'string',
54 1
				ApiBase::PARAM_REQUIRED => true
55 1
			],
56
			'query' => [
57 1
				ApiBase::PARAM_TYPE => 'string',
58 1
				ApiBase::PARAM_REQUIRED => true
59 1
			],
60
			'sep' => [
61 1
				ApiBase::PARAM_TYPE => 'string',
62 1
				ApiBase::PARAM_REQUIRED => false
63 1
			]
64 1
		];
65
	}
66
67
	/**
68
	 * @see ApiBase::getDescription
69
	 */
70
	public function getDescription() {
71
		return [
72
			'API for providing SemanticFormsSelect values'
73
		];
74
	}
75
76
	/**
77
	 * @see ApiBase::getParamDescription
78
	 */
79
	public function getParamDescription() {
80
		return [
81
			'approach' => 'The actual approach: function or smw',
82
			'query' => 'The query of the former'
83
		];
84
	}
85
86
	/**
87
	 * @see ApiBase::getVersion
88
	 */
89
	public function getVersion() {
90
		return __CLASS__ . ': 1.1';
91
	}
92
93
	// Compatibility helper for MW < 1.32
94
	private function getParser(): Parser {
95
		if ( class_exists( \MediaWiki\MediaWikiServices::class ) ) {
96
			$services = \MediaWiki\MediaWikiServices::getInstance();
97
			if ( is_callable( $services, 'getParserFactory' ) ) {
98
				return $services->getParserFactory()->create();
0 ignored issues
show
Bug introduced by
The method getParserFactory cannot be called on $services (of type callable).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
99
			}
100
		}
101
		return new Parser( $GLOBALS['wgParserConf'] );
102
	}
103
104
}
105