Completed
Push — master ( f60d39...557493 )
by mw
12:54 queued 11:30
created

ScribuntoLuaLibrary   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 90.63%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 78
ccs 29
cts 32
cp 0.9063
rs 10
c 2
b 0
f 0
wmc 6
lcom 0
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 9 1
B getQueryResult() 0 25 2
A getPropertyType() 0 17 3
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
	/**
22
	 * @since 1.0
23
	 */
24 5
	public function register() {
25
26
		$lib = array(
27 5
			'getQueryResult'  => array( $this, 'getQueryResult' ),
28 5
			'getPropertyType' => array( $this, 'getPropertyType' ),
29 5
		);
30
31 5
		$this->getEngine()->registerInterface( __DIR__ . '/' . 'mw.ext.smw.lua', $lib, array() );
32 5
	}
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
	 *
41
	 * @return array
42
	 */
43 2
	public function getQueryResult( $argString = null ) {
44
45 2
		$rawParameters = preg_split( "/(?<=[^\|])\|(?=[^\|])/", $argString );
46
47 2
		list( $queryString, $parameters, $printouts ) = QueryProcessor::getComponentsFromFunctionParams(
48 2
		    $rawParameters,
49
		    false
50 2
		);
51
52 2
		QueryProcessor::addThisPrintout( $printouts, $parameters );
53
54 2
		$query = QueryProcessor::createQuery(
55 2
		    $queryString,
56 2
		    QueryProcessor::getProcessedParams( $parameters, $printouts ),
57 2
		    QueryProcessor::SPECIAL_PAGE,
58 2
		    '',
59
		    $printouts
60 2
		);
61
62 2
		$queryResult = ApplicationFactory::getInstance()->getStore()->getQueryResult( $query )->toArray();
63 2
		if(!empty($queryResult["results"])) {
64
		    $queryResult["results"] = array_combine(range(1, count($queryResult["results"])), array_values($queryResult["results"]));
65
		}
66 2
		return array( $queryResult );
67
	}
68
69
	/**
70
	 * Returns property type
71
	 *
72
	 * @since 1.0
73
	 *
74
	 * @param string $propertyName
75
	 *
76
	 * @return array
77
	 */
78 3
	public function getPropertyType( $propertyName = null ) {
79
80 3
		$this->checkType( 'getPropertyType', 1, $propertyName, 'string' );
81 3
		$propertyName = trim( $propertyName );
82
83 3
		if ( $propertyName === '' ) {
84 1
			return array( null );
85
		}
86
87 2
		$property = DIProperty::newFromUserLabel( $propertyName );
88
89 2
		if ( $property === null ) {
90
			return array( null );
91
		}
92
93 2
		return array( $property->findPropertyTypeID() );
94
	}
95
96
}
97