Completed
Push — master ( aed6e5...706a8d )
by mw
18:05
created

src/ResourceFormatter.php (1 issue)

parameters are used.

Unused Code Minor

Upgrade to new PHP Analysis Engine

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 SRF;
4
5
use Html;
6
use SMWOutputs as ResourceManager;
7
use SMWQueryResult as QueryResult;
8
9
/**
10
 * @since 3.0
11
 *
12
 * @license GNU GPL v2 or later
13
 * @author mwjames
14
 */
15
class ResourceFormatter {
16
17
	/**
18
	 * @since 3.0
19
	 *
20
	 * @param array $modules
21
	 * @param array $styleModules
22
	 */
23
	public static function registerResources( array $modules = [], array $styleModules = [] ) {
24
25
		foreach ( $modules as $module ) {
26
			ResourceManager::requireResource( $module );
27
		}
28
29
		foreach ( $styleModules as $styleModule ) {
30
			ResourceManager::requireStyle( $styleModule );
31
		}
32
	}
33
34
	/**
35
	 * @since 3.0
36
	 *
37
	 * @return string
38
	 */
39
	public static function session() {
40
		return 'smw-' . uniqid();
41
	}
42
43
	/**
44
	 * Convenience method generating a visual placeholder before any
45
	 * JS is registered to indicate that resources (JavaScript, CSS)
46
	 * are being loaded and once ready ensure to set
47
	 * ( '.smw-spinner' ).hide()
48
	 *
49
	 * @since 3.0
50
	 */
51
	public static function placeholder() {
52
		self::registerResources( [], [ 'ext.smw.style' ] );
53
54
		return Html::rawElement(
55
			'div',
56
			array( 'class' => 'smw-spinner left mw-small-spinner' ),
57
			Html::element(
58
				'p',
59
				array( 'class' => 'text' ),
60
				wfMessage( 'smw-livepreview-loading' )->text()
61
			)
62
		);
63
	}
64
65
	/**
66
	 *
67
	 * @since 3.0
68
	 *
69
	 * @param string $id
70
	 * @param array $data
71
	 */
72
	public static function encode( $id, $data ) {
73
		ResourceManager::requireHeadItem(
74
			$id,
75
			\Skin::makeVariablesScript(
76
				[
77
					$id => json_encode( $data )
78
				]
79
			)
80
		);
81
	}
82
83
	/**
84
	 * @param QueryResult $queryResult
85
	 * @param $outputMode
86
	 *
87
	 * @return string
88
	 */
89
	public static function getData( QueryResult $queryResult, $outputMode, $parameters = [] ) {
0 ignored issues
show
The parameter $outputMode is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
90
91
		// Add parameters that are only known to the specific printer
92
		$ask = $queryResult->getQuery()->toArray();
93
94
		foreach ( $parameters as $key => $value ) {
95
			if ( is_string( $value ) || is_integer( $value ) || is_bool( $value ) ) {
96
				$ask['parameters'][$key] = $value;
97
			}
98
		}
99
100
		// Combine all data into one object
101
		$data = array(
102
			'query' => array(
103
				'result' => $queryResult->toArray(),
104
				'ask'    => $ask
105
			)
106
		);
107
108
		return $data;
109
	}
110
111
}
112