SemanticMediaWiki /
SemanticScribunto
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 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
|
|||
| 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 |
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
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.