Completed
Push — master ( 27085c...bdd9af )
by mw
17:29
created

ScribuntoLuaLibrary::getQueryResult()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
dl 0
loc 25
rs 8.8571
c 2
b 0
f 0
eloc 16
nc 2
nop 1
ccs 11
cts 11
cp 1
crap 2
1
<?php
2
3
namespace SMW\Scribunto;
4
5
use Scribunto_LuaLibraryBase;
6
use SMW\DIProperty;
7
use FauxRequest;
8
use ApiMain;
9
10
use SMWQueryProcessor as QueryProcessor;
11
use SMW\ApplicationFactory;
12
13
/**
14
 * @license GNU GPL v2+
15
 * @since 1.0
16
 *
17
 * @author mwjames
18
 */
19
class ScribuntoLuaLibrary extends Scribunto_LuaLibraryBase {
20
21 5
	/**
22
	 * @since 1.0
23
	 */
24 5
	public function register() {
25 5
26 5
		$lib = array(
27
			'getQueryResult'  => array( $this, 'getQueryResult' ),
28 5
			'getPropertyType' => array( $this, 'getPropertyType' ),
29 5
		);
30
31
		$this->getEngine()->registerInterface( __DIR__ . '/' . 'mw.ext.smw.lua', $lib, array() );
32
	}
33
34
	/**
35
	 * Returns query results in for of the standard API return format
36
	 *
37
	 * @since 1.0
38
	 *
39
	 * @param string $queryString
0 ignored issues
show
Bug introduced by
There is no parameter named $queryString. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
40 2
	 *
41
	 * @return array
42 2
	 */
43 2
	public function getQueryResult( $argString = null ) {
44
45 2
		$rawParameters = preg_split( "/(?<=[^\|])\|(?=[^\|])/", $argString );
46 1
47
		list( $queryString, $parameters, $printouts ) = QueryProcessor::getComponentsFromFunctionParams(
48
		    $rawParameters,
49 1
		    false
50
		);
51 1
52
		QueryProcessor::addThisPrintout( $printouts, $parameters );
53 1
54 1
		$query = QueryProcessor::createQuery(
55
		    $queryString,
56 1
		    QueryProcessor::getProcessedParams( $parameters, $printouts ),
57 1
		    QueryProcessor::SPECIAL_PAGE,
58 1
		    '',
59
		    $printouts
60 1
		);
61
62
		$queryResult = ApplicationFactory::getInstance()->getStore()->getQueryResult( $query )->toArray();
63
		if(!empty($queryResult["results"])) {
64
		    $queryResult["results"] = array_combine(range(1, count($queryResult["results"])), array_values($queryResult["results"]));
65
		}
66
		return array( $queryResult );
67
	}
68
69
	/**
70
	 * Returns property type
71
	 *
72 3
	 * @since 1.0
73
	 *
74 3
	 * @param string $propertyName
75 3
	 *
76
	 * @return array
77 3
	 */
78 1
	public function getPropertyType( $propertyName = null ) {
79
80
		$this->checkType( 'getPropertyType', 1, $propertyName, 'string' );
81 2
		$propertyName = trim( $propertyName );
82
83 2
		if ( $propertyName === '' ) {
84
			return array( null );
85
		}
86
87 2
		$property = DIProperty::newFromUserLabel( $propertyName );
88
89
		if ( $property === null ) {
90
			return array( null );
91
		}
92
93
		return array( $property->findPropertyTypeID() );
94
	}
95
96
}
97