Completed
Push — master ( 009a56...ff47c8 )
by mw
17:58
created

LibraryFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 3
cts 3
cp 1
crap 1
rs 10
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 5
	public function __construct( Store $store ) {
30 5
		$this->store = $store;
31 5
	}
32
33
	/**
34
	 * @since 1.0
35
	 *
36
	 * @param string|array $rawParameters
37
	 *
38
	 * @return QueryResult
39
	 */
40 1
	public function newQueryResultFrom( $rawParameters ) {
41
42 1
		list( $queryString, $parameters, $printouts ) = QueryProcessor::getComponentsFromFunctionParams(
43 1
			$rawParameters,
0 ignored issues
show
Bug introduced by
It seems like $rawParameters can also be of type string; however, SMWQueryProcessor::getCo...ntsFromFunctionParams() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
44
			false
45 1
		);
46
47 1
		QueryProcessor::addThisPrintout( $printouts, $parameters );
48
49 1
		$query = QueryProcessor::createQuery(
50 1
			$queryString,
51 1
			QueryProcessor::getProcessedParams( $parameters, $printouts ),
52 1
			QueryProcessor::SPECIAL_PAGE,
53 1
			'',
54
			$printouts
55 1
		);
56
57 1
		return $this->store->getQueryResult( $query );
58
	}
59
60
	/**
61
	 * @since 1.0
62
	 *
63
	 * @param array $arguments
64
	 *
65
	 * @return ParserParameterProcessor
66
	 */
67 1
	public function newParserParameterProcessorFrom( $arguments ) {
68 1
		return ParameterProcessorFactory::newFromArray( $arguments );
69
	}
70
71
	/**
72
	 * @since 1.0
73
	 *
74
	 * @param Parser $parser
75
	 *
76
	 * @return SetParserFunction
77
	 */
78 1
	public function newSetParserFunction( Parser $parser ) {
79 1
		return ApplicationFactory::getInstance()->newParserFunctionFactory( $parser )->newSetParserFunction( $parser );
80
	}
81
82
	/**
83
	 * @since 1.0
84
	 *
85
	 * @param Parser $parser
86
	 *
87
	 * @return SubobjectParserFunction
88
	 */
89 1
	public function newSubobjectParserFunction( Parser $parser ) {
90 1
		return ApplicationFactory::getInstance()->newParserFunctionFactory( $parser )->newSubobjectParserFunction( $parser );
91
	}
92
93
}
94