Completed
Pull Request — master (#59)
by
unknown
05:02
created

ApiSemanticFormsSelect   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 74
rs 10
c 0
b 0
f 0
ccs 0
cts 46
cp 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 21 1
A getAllowedParams() 0 16 1
A getDescription() 0 5 1
A getParamDescription() 0 6 1
A getVersion() 0 3 1
1
<?php
2
3
//namespace SFS;	# for some reason, this was not working with API registration via extension.json
4
5
use ApiBase;
6
use Parser;
7
use ParserOptions;
8
use ParserOutput;
9
use Title;
10
11
/**
12
 * API modules to communicate with the back-end
13
 *
14
 * @license GNU GPL v2+
15
 * @since 1.2
16
 *
17
 * @author Jason Zhang
18
 * @author Toni Hermoso Pulido
19
 */
20
class ApiSemanticFormsSelect extends ApiBase {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
21
22
	/**
23
	 * @see ApiBase::execute
24
	 */
25
	public function execute() {
0 ignored issues
show
Coding Style introduced by
execute uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
26
27
		$parser = new Parser( $GLOBALS['wgParserConf'] );
28
		$parser->setTitle( Title::newFromText( 'NO TITLE' ) );
29
		$parser->mOptions = new ParserOptions();
30
		$parser->mOutput = new ParserOutput();
31
32
		$apiRequestProcessor = new SFS\ApiSemanticFormsSelectRequestProcessor( $parser );
33
		$apiRequestProcessor->setDebugFlag( $GLOBALS['wgSF_Select_debug'] );
34
35
		$resultValues = $apiRequestProcessor->getJsonDecodedResultValuesForRequestParameters(
36
			$this->extractRequestParams()
37
		);
38
39
		$result = $this->getResult();
40
		$result->setIndexedTagName( $resultValues->values, 'value' );
41
		$result->addValue( $this->getModuleName(), 'values', $resultValues->values );
42
		$result->addValue( $this->getModuleName(), 'count', $resultValues->count );
43
44
		return true;
45
	}
46
47
	/**
48
	 * @see ApiBase::getAllowedParams
49
	 */
50
	public function getAllowedParams() {
51
		return array(
52
			'approach' => array(
53
				ApiBase::PARAM_TYPE => 'string',
54
				ApiBase::PARAM_REQUIRED => true
55
			),
56
			'query' => array(
57
				ApiBase::PARAM_TYPE => 'string',
58
				ApiBase::PARAM_REQUIRED => true
59
			),
60
			'sep' => array(
61
				ApiBase::PARAM_TYPE => 'string',
62
				ApiBase::PARAM_REQUIRED => false
63
			)
64
		);
65
	}
66
67
	/**
68
	 * @see ApiBase::getDescription
69
	 */
70
	public function getDescription() {
71
		return array(
72
			'API for providing SemanticFormsSelect values'
73
		);
74
	}
75
76
	/**
77
	 * @see ApiBase::getParamDescription
78
	 */
79
	public function getParamDescription() {
80
		return array(
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
}
94