Completed
Push — master ( 3132df...b84890 )
by mw
03:02
created

LibraryFactory::newLuaAskResultProcessor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SMW\Scribunto;
4
5
use SMWQueryProcessor as QueryProcessor;
6
use SMW\Store;
7
use SMW\ApplicationFactory;
8
use SMW\ParameterProcessorFactory;
9
use Parser;
10
11
/**
12
 * @license GNU GPL v2+
13
 * @since 1.0
14
 *
15
 * @author mwjames
16
 */
17
class LibraryFactory {
18
19
	/**
20
	 *@var Store
21
	 */
22
	private $store;
23
24
	/**
25
	 * @since 1.0
26
	 *
27
	 * @param Store $store
28
	 */
29 6
	public function __construct( Store $store ) {
30 6
		$this->store = $store;
31 6
	}
32
33
	/**
34
	 * Creates a new SMWQueryResult from passed arguments,
35
	 * utilizing the {@see SMWQueryProcessor}
36
	 *
37
	 * @since 1.0
38
	 *
39
	 * @param array $rawParameters
40
	 *
41
	 * @return \SMWQueryResult
42
	 */
43 1
	public function newQueryResultFrom( $rawParameters ) {
44
45 1
		list( $queryString, $parameters, $printouts ) = QueryProcessor::getComponentsFromFunctionParams(
46 1
			$rawParameters,
47
			false
48 1
		);
49
50 1
		QueryProcessor::addThisPrintout( $printouts, $parameters );
51
52 1
		$query = QueryProcessor::createQuery(
53 1
			$queryString,
54 1
			QueryProcessor::getProcessedParams( $parameters, $printouts ),
55 1
			QueryProcessor::SPECIAL_PAGE,
56 1
			'',
57
			$printouts
58 1
		);
59
60 1
		return $this->store->getQueryResult( $query );
61
	}
62
63
	/**
64
	 * @since 1.0
65
	 *
66
	 * @param QueryResult|string $queryResult
67
	 *
68
	 * @return LuaAskResultProcessor
69
	 */
70 1
	public function newLuaAskResultProcessor( $queryResult ) {
71 1
		return new LuaAskResultProcessor( $queryResult );
0 ignored issues
show
Bug introduced by
It seems like $queryResult defined by parameter $queryResult on line 70 can also be of type string; however, SMW\Scribunto\LuaAskResultProcessor::__construct() does only seem to accept object<SMWQueryResult>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
72
	}
73
74
	/**
75
	 * Creates a new ParserParameterProcessor from passed arguments
76
	 *
77
	 * @since 1.0
78
	 *
79
	 * @param array $arguments
80
	 *
81
	 * @return \SMW\ParserParameterProcessor
82
	 */
83 1
	public function newParserParameterProcessorFrom( $arguments ) {
84 1
		return ParameterProcessorFactory::newFromArray( $arguments );
85
	}
86
87
	/**
88
	 * Creates a new SetParserFunction utilizing a Parser
89
	 *
90
	 * @since 1.0
91
	 *
92
	 * @param Parser $parser
93
	 *
94
	 * @return \SMW\SetParserFunction
95
	 */
96 1
	public function newSetParserFunction( Parser $parser ) {
97 1
		return ApplicationFactory::getInstance()->newParserFunctionFactory( $parser )->newSetParserFunction( $parser );
98
	}
99
100
	/**
101
	 * Creates a new SubobjectParserFunction utilizing a Parser
102
	 *
103
	 * @since 1.0
104
	 *
105
	 * @param Parser $parser
106
	 *
107
	 * @return \SMW\SubobjectParserFunction
108
	 */
109 1
	public function newSubobjectParserFunction( Parser $parser ) {
110 1
		return ApplicationFactory::getInstance()->newParserFunctionFactory( $parser )->newSubobjectParserFunction( $parser );
111
	}
112
}
113