Completed
Pull Request — master (#140)
by
unknown
13s
created
src/ApiSemanticFormsSelectRequestProcessor.php 1 patch
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	 * @since 1.3
37 37
 	 *
38 38
 	 */
39
-	public function __construct( Parser $parser, $getSmwResultFromFunctionParams = null ) {
39
+	public function __construct(Parser $parser, $getSmwResultFromFunctionParams = null) {
40 40
 		$this->parser = $parser;
41 41
 		$this->getSmwResultFromFunctionParams = $getSmwResultFromFunctionParams
42 42
 			?? '\SFS\ApiSemanticFormsSelectRequestProcessor::defaultGetSmwResultFromFunctionParams';
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 	 *
48 48
 	 * @param boolean $debugFlag
49 49
 	 */
50
-	public function setDebugFlag( $debugFlag ) {
50
+	public function setDebugFlag($debugFlag) {
51 51
 		$this->debugFlag = $debugFlag;
52 52
 	}
53 53
 
@@ -58,14 +58,14 @@  discard block
 block discarded – undo
58 58
 	 *
59 59
 	 * @return string
60 60
 	 */
61
-	public function getJsonDecodedResultValuesForRequestParameters( array $parameters ) {
61
+	public function getJsonDecodedResultValuesForRequestParameters(array $parameters) {
62 62
 
63
-		if ( !isset( $parameters['query'] ) || !isset( $parameters['sep'] ) ) {
64
-			throw new InvalidArgumentException( 'Missing an query parameter' );
63
+		if (!isset($parameters['query']) || !isset($parameters['sep'])) {
64
+			throw new InvalidArgumentException('Missing an query parameter');
65 65
 		}
66 66
 
67
-		if ( !isset( $parameters['query'] ) || !isset( $parameters['sep'] ) ) {
68
-			throw new InvalidArgumentException( 'Missing an query parameter' );
67
+		if (!isset($parameters['query']) || !isset($parameters['sep'])) {
68
+			throw new InvalidArgumentException('Missing an query parameter');
69 69
 		}
70 70
 
71 71
 		$this->parser->firstCallInit();
@@ -73,97 +73,97 @@  discard block
 block discarded – undo
73 73
 		$this->parser->setOutputType(Parser::OT_HTML);
74 74
 		$json = [];
75 75
 
76
-		if ( isset( $parameters['approach'] ) && $parameters['approach'] == 'smw' ) {
77
-			$json = $this->doProcessQueryFor( $parameters['query'], $parameters['sep'] );
76
+		if (isset($parameters['approach']) && $parameters['approach'] == 'smw') {
77
+			$json = $this->doProcessQueryFor($parameters['query'], $parameters['sep']);
78 78
 		} else {
79
-			$json = $this->doProcessFunctionFor( $parameters['query'], $parameters['sep'] );
79
+			$json = $this->doProcessFunctionFor($parameters['query'], $parameters['sep']);
80 80
 		}
81 81
 
82 82
 		// I have no idea why we first encode and and then decode here??
83 83
 
84
-		return json_decode( $json );
84
+		return json_decode($json);
85 85
 	}
86 86
 
87
-	private function doProcessQueryFor( $querystr, $sep = "," ) {
87
+	private function doProcessQueryFor($querystr, $sep = ",") {
88 88
 
89 89
 		$querystr = str_replace(
90
-			[ "<", ">", "sep=;" ],
91
-			[ "<", ">", "sep={$sep};" ],
90
+			["&lt;", "&gt;", "sep=;"],
91
+			["<", ">", "sep={$sep};"],
92 92
 			$querystr
93 93
 		);
94 94
 
95
-		$rawparams = $this->extractRawParameters( $querystr );
96
-		$f = str_replace( ";", "|", $rawparams[0] );
97
-		$rawparams[0] = $this->parser->replaceVariables( $f );
95
+		$rawparams = $this->extractRawParameters($querystr);
96
+		$f = str_replace(";", "|", $rawparams[0]);
97
+		$rawparams[0] = $this->parser->replaceVariables($f);
98 98
 
99
-		if ( $this->debugFlag ) {
100
-			error_log( implode( "|", $rawparams ) );
99
+		if ($this->debugFlag) {
100
+			error_log(implode("|", $rawparams));
101 101
 		}
102 102
 
103 103
 		$result = ($this->getSmwResultFromFunctionParams)($rawparams);
104 104
 
105
-		$values = $this->getFormattedValuesFrom( $sep, $result );
105
+		$values = $this->getFormattedValuesFrom($sep, $result);
106 106
 
107
-		return json_encode( [
107
+		return json_encode([
108 108
 			"values" => $values,
109
-			"count"  => count( $values )
110
-		] );
109
+			"count"  => count($values)
110
+		]);
111 111
 	}
112 112
 
113
-	private function extractRawParameters( $querystr ) {
113
+	private function extractRawParameters($querystr) {
114 114
 		$ensureParameter = function($name, $value) use (&$rawparams) {
115 115
 			$rawparams = array_filter($rawparams, function($param) use ($name) {
116
-				return substr_compare( $param, "$name=", 0, strlen( "$name=" ) ) !== 0;
116
+				return substr_compare($param, "$name=", 0, strlen("$name=")) !== 0;
117 117
 			});
118 118
 			if ($value !== null)
119 119
 				$rawparams[] = "$name=$value";
120 120
 		};
121 121
 
122
-		$rawparams = explode( ";", $querystr );
122
+		$rawparams = explode(";", $querystr);
123 123
 		// The JavaScript part expects plainlist format for parsing
124 124
 		$ensureParameter('format', 'plainlist');
125 125
 
126 126
 		return $rawparams;
127 127
 	}
128 128
 
129
-	private function doProcessFunctionFor( $query, $sep = "," ) {
129
+	private function doProcessFunctionFor($query, $sep = ",") {
130 130
 
131 131
 		$query = str_replace(
132
-			[ "&lt;", "&gt;", "sep=;" ],
133
-			[ "<", ">", "sep={$sep};" ],
132
+			["&lt;", "&gt;", "sep=;"],
133
+			["<", ">", "sep={$sep};"],
134 134
 			$query
135 135
 		);
136 136
 
137
-		$f = str_replace( ";", "|", $query );
137
+		$f = str_replace(";", "|", $query);
138 138
 
139
-		if ( $this->debugFlag ) {
140
-			error_log( $f );
139
+		if ($this->debugFlag) {
140
+			error_log($f);
141 141
 		}
142 142
 
143 143
 		$values = $this->getFormattedValuesFrom(
144 144
 			$sep,
145
-			$this->parser->replaceVariables( $f )
145
+			$this->parser->replaceVariables($f)
146 146
 		);
147 147
 
148
-		return json_encode( [
148
+		return json_encode([
149 149
 			"values" => $values,
150
-			"count"  => count( $values )
151
-		] );
150
+			"count"  => count($values)
151
+		]);
152 152
 	}
153 153
 
154
-	private function getFormattedValuesFrom( $sep, $values ) {
154
+	private function getFormattedValuesFrom($sep, $values) {
155 155
 
156
-		if ( strpos( $values ?? '', $sep ) === false ) {
157
-			return [ $values ];
156
+		if (strpos($values ?? '', $sep) === false) {
157
+			return [$values];
158 158
 		}
159 159
 
160
-		$values = explode( $sep, $values );
161
-		$values = array_map( "trim", $values );
162
-		$values = array_unique( $values );
160
+		$values = explode($sep, $values);
161
+		$values = array_map("trim", $values);
162
+		$values = array_unique($values);
163 163
 
164 164
 		// TODO: sorting here will destroy any sort defined in the query, e.g. in case sorting for labels (instead of mainlable)
165 165
 		//sort( $values );
166
-		array_unshift( $values, "" );
166
+		array_unshift($values, "");
167 167
 
168 168
 		return $values;
169 169
 	}
@@ -172,14 +172,14 @@  discard block
 block discarded – undo
172 172
 	 * @param $rawparams
173 173
 	 * @return string
174 174
 	 */
175
-	private static function defaultGetSmwResultFromFunctionParams( $rawparams ): string {
176
-		list( $query, $params ) =
177
-			SMWQueryProcessor::getQueryAndParamsFromFunctionParams( $rawparams, SMW_OUTPUT_WIKI,
178
-				SMWQueryProcessor::INLINE_QUERY, false );
175
+	private static function defaultGetSmwResultFromFunctionParams($rawparams): string {
176
+		list($query, $params) =
177
+			SMWQueryProcessor::getQueryAndParamsFromFunctionParams($rawparams, SMW_OUTPUT_WIKI,
178
+				SMWQueryProcessor::INLINE_QUERY, false);
179 179
 
180 180
 		$result =
181
-			SMWQueryProcessor::getResultFromQuery( $query, $params, SMW_OUTPUT_WIKI,
182
-				SMWQueryProcessor::INLINE_QUERY );
181
+			SMWQueryProcessor::getResultFromQuery($query, $params, SMW_OUTPUT_WIKI,
182
+				SMWQueryProcessor::INLINE_QUERY);
183 183
 
184 184
 		return $result;
185 185
 	}
Please login to merge, or discard this patch.