Completed
Push — master ( 017c6f...1c52d4 )
by Bene
35:29 queued 22s
created
src/QueryBuilder.php 2 patches
Doc Comments   +10 added lines, -7 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 	/**
84 84
 	 * Specifies the expressions to select.
85 85
 	 *
86
-	 * @param string|string[] $expressions
86
+	 * @param string $expressions
87 87
 	 * @return self
88 88
 	 * @throws InvalidArgumentException
89 89
 	 * @throws RuntimeException
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 	 *
103 103
 	 * @since 0.3
104 104
 	 *
105
-	 * @param string|string[] $expressions
105
+	 * @param string $expressions
106 106
 	 * @return self
107 107
 	 * @throws InvalidArgumentException
108 108
 	 * @throws RuntimeException
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 	 *
123 123
 	 * @since 0.3
124 124
 	 *
125
-	 * @param string|string[] $expressions
125
+	 * @param string $expressions
126 126
 	 * @return self
127 127
 	 * @throws InvalidArgumentException
128 128
 	 * @throws RuntimeException
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 	 *
143 143
 	 * @since 0.4
144 144
 	 *
145
-	 * @param string|string[] $expressions
145
+	 * @param string $expressions
146 146
 	 * @return self
147 147
 	 * @throws InvalidArgumentException
148 148
 	 * @throws RuntimeException
@@ -160,6 +160,9 @@  discard block
 block discarded – undo
160 160
 		return $this;
161 161
 	}
162 162
 
163
+	/**
164
+	 * @param string $queryForm
165
+	 */
163 166
 	private function setQueryForm( $queryForm ) {
164 167
 		if ( $this->queryForm !== null ) {
165 168
 			throw new RuntimeException( 'Query type is already set to ' . $this->queryForm );
@@ -251,7 +254,7 @@  discard block
 block discarded – undo
251 254
 	 *
252 255
 	 * @since 0.3
253 256
 	 *
254
-	 * @param string|GraphBuilder $subject
257
+	 * @param GraphBuilder $subject
255 258
 	 * @param string|null $predicate
256 259
 	 * @param string|null $object
257 260
 	 * @return self
@@ -283,7 +286,7 @@  discard block
 block discarded – undo
283 286
 	 *
284 287
 	 * @since 0.3
285 288
 	 *
286
-	 * @param GraphBuilder|GraphBuilder[] $graphs
289
+	 * @param GraphBuilder $graphs
287 290
 	 * @return self
288 291
 	 * @throws InvalidArgumentException
289 292
 	 */
@@ -327,7 +330,7 @@  discard block
 block discarded – undo
327 330
 	/**
328 331
 	 * Sets the GROUP BY modifier.
329 332
 	 *
330
-	 * @param string|string[] $expressions
333
+	 * @param string $expressions
331 334
 	 * @return self
332 335
 	 * @throws InvalidArgumentException
333 336
 	 */
Please login to merge, or discard this patch.
Spacing   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -63,12 +63,12 @@  discard block
 block discarded – undo
63 63
 	 * @var string[] $prefixes
64 64
 	 * @throws InvalidArgumentException
65 65
 	 */
66
-	public function __construct( array $prefixes = array() ) {
66
+	public function __construct(array $prefixes = array()) {
67 67
 		$this->expressionValidator = new ExpressionValidator();
68 68
 		$this->usageValidator = new UsageValidator();
69
-		$this->prefixBuilder = new QueryPrefixBuilder( $prefixes, $this->usageValidator );
70
-		$this->graphBuilder = new GraphBuilder( $this->usageValidator );
71
-		$this->modifierBuilder = new QueryModifierBuilder( $this->usageValidator );
69
+		$this->prefixBuilder = new QueryPrefixBuilder($prefixes, $this->usageValidator);
70
+		$this->graphBuilder = new GraphBuilder($this->usageValidator);
71
+		$this->modifierBuilder = new QueryModifierBuilder($this->usageValidator);
72 72
 	}
73 73
 
74 74
 	/**
@@ -88,11 +88,11 @@  discard block
 block discarded – undo
88 88
 	 * @throws InvalidArgumentException
89 89
 	 * @throws RuntimeException
90 90
 	 */
91
-	public function select( $expressions /* expressions ... */ ) {
92
-		$expressions = is_array( $expressions ) ? $expressions : func_get_args();
91
+	public function select($expressions /* expressions ... */) {
92
+		$expressions = is_array($expressions) ? $expressions : func_get_args();
93 93
 
94
-		$this->setQueryForm( 'SELECT' );
95
-		$this->addExpressions( $expressions );
94
+		$this->setQueryForm('SELECT');
95
+		$this->addExpressions($expressions);
96 96
 
97 97
 		return $this;
98 98
 	}
@@ -107,12 +107,12 @@  discard block
 block discarded – undo
107 107
 	 * @throws InvalidArgumentException
108 108
 	 * @throws RuntimeException
109 109
 	 */
110
-	public function selectDistinct( $expressions /* expressions ... */ ) {
111
-		$expressions = is_array( $expressions ) ? $expressions : func_get_args();
110
+	public function selectDistinct($expressions /* expressions ... */) {
111
+		$expressions = is_array($expressions) ? $expressions : func_get_args();
112 112
 
113
-		$this->setQueryForm( 'SELECT' );
113
+		$this->setQueryForm('SELECT');
114 114
 		$this->uniqueness = 'DISTINCT ';
115
-		$this->addExpressions( $expressions );
115
+		$this->addExpressions($expressions);
116 116
 
117 117
 		return $this;
118 118
 	}
@@ -127,12 +127,12 @@  discard block
 block discarded – undo
127 127
 	 * @throws InvalidArgumentException
128 128
 	 * @throws RuntimeException
129 129
 	 */
130
-	public function selectReduced( $expressions /* expressions ... */ ) {
131
-		$expressions = is_array( $expressions ) ? $expressions : func_get_args();
130
+	public function selectReduced($expressions /* expressions ... */) {
131
+		$expressions = is_array($expressions) ? $expressions : func_get_args();
132 132
 
133
-		$this->setQueryForm( 'SELECT' );
133
+		$this->setQueryForm('SELECT');
134 134
 		$this->uniqueness = 'REDUCED ';
135
-		$this->addExpressions( $expressions );
135
+		$this->addExpressions($expressions);
136 136
 
137 137
 		return $this;
138 138
 	}
@@ -147,10 +147,10 @@  discard block
 block discarded – undo
147 147
 	 * @throws InvalidArgumentException
148 148
 	 * @throws RuntimeException
149 149
 	 */
150
-	public function describe( $expressions /* expressions ... */ ) {
151
-		$expressions = is_array( $expressions ) ? $expressions : func_get_args();
150
+	public function describe($expressions /* expressions ... */) {
151
+		$expressions = is_array($expressions) ? $expressions : func_get_args();
152 152
 
153
-		$this->setQueryForm( 'DESCRIBE' );
153
+		$this->setQueryForm('DESCRIBE');
154 154
 		$this->addExpressions(
155 155
 			$expressions,
156 156
 			ExpressionValidator::VALIDATE_VARIABLE | ExpressionValidator::VALIDATE_FUNCTION_AS
@@ -160,16 +160,16 @@  discard block
 block discarded – undo
160 160
 		return $this;
161 161
 	}
162 162
 
163
-	private function setQueryForm( $queryForm ) {
164
-		if ( $this->queryForm !== null ) {
165
-			throw new RuntimeException( 'Query type is already set to ' . $this->queryForm );
163
+	private function setQueryForm($queryForm) {
164
+		if ($this->queryForm !== null) {
165
+			throw new RuntimeException('Query type is already set to ' . $this->queryForm);
166 166
 		}
167 167
 
168 168
 		$this->queryForm = $queryForm;
169 169
 	}
170 170
 
171
-	private function addExpressions( array $expressions, $options = null ) {
172
-		foreach ( $expressions as $expression ) {
171
+	private function addExpressions(array $expressions, $options = null) {
172
+		foreach ($expressions as $expression) {
173 173
 			$this->expressionValidator->validate(
174 174
 				$expression,
175 175
 				$options ?: ExpressionValidator::VALIDATE_VARIABLE | ExpressionValidator::VALIDATE_FUNCTION_AS
@@ -177,12 +177,12 @@  discard block
 block discarded – undo
177 177
 
178 178
 			// @todo temp hack to add AS definitions to defined variables
179 179
 			$regexHelper = new RegexHelper();
180
-			$matches = $regexHelper->getMatches( 'AS \{variable}', $expression );
181
-			$this->usageValidator->trackDefinedVariables( $matches );
180
+			$matches = $regexHelper->getMatches('AS \{variable}', $expression);
181
+			$this->usageValidator->trackDefinedVariables($matches);
182 182
 
183 183
 			// @todo detect functions and wrap with brackets automatically
184
-			$this->usageValidator->trackUsedVariables( $expression );
185
-			$this->usageValidator->trackUsedPrefixes( $expression );
184
+			$this->usageValidator->trackUsedVariables($expression);
185
+			$this->usageValidator->trackUsedPrefixes($expression);
186 186
 			$this->selects[] = $expression;
187 187
 		}
188 188
 	}
@@ -196,8 +196,8 @@  discard block
 block discarded – undo
196 196
 	 * @return self
197 197
 	 * @throws InvalidArgumentException
198 198
 	 */
199
-	public function where( $subject, $predicate, $object ) {
200
-		$this->graphBuilder->where( $subject, $predicate, $object );
199
+	public function where($subject, $predicate, $object) {
200
+		$this->graphBuilder->where($subject, $predicate, $object);
201 201
 		return $this;
202 202
 	}
203 203
 
@@ -211,8 +211,8 @@  discard block
 block discarded – undo
211 211
 	 * @return self
212 212
 	 * @throws InvalidArgumentException
213 213
 	 */
214
-	public function also( $subject, $predicate = null, $object = null ) {
215
-		$this->graphBuilder->also( $subject, $predicate, $object );
214
+	public function also($subject, $predicate = null, $object = null) {
215
+		$this->graphBuilder->also($subject, $predicate, $object);
216 216
 		return $this;
217 217
 	}
218 218
 
@@ -227,8 +227,8 @@  discard block
 block discarded – undo
227 227
 	 * @return self
228 228
 	 * @throws InvalidArgumentException
229 229
 	 */
230
-	public function optional( $subject, $predicate = null, $object = null ) {
231
-		$this->graphBuilder->optional( $subject, $predicate, $object );
230
+	public function optional($subject, $predicate = null, $object = null) {
231
+		$this->graphBuilder->optional($subject, $predicate, $object);
232 232
 		return $this;
233 233
 	}
234 234
 
@@ -241,8 +241,8 @@  discard block
 block discarded – undo
241 241
 	 * @return self
242 242
 	 * @throws InvalidArgumentException
243 243
 	 */
244
-	public function filter( $expression ) {
245
-		$this->graphBuilder->filter( $expression );
244
+	public function filter($expression) {
245
+		$this->graphBuilder->filter($expression);
246 246
 		return $this;
247 247
 	}
248 248
 
@@ -257,8 +257,8 @@  discard block
 block discarded – undo
257 257
 	 * @return self
258 258
 	 * @throws InvalidArgumentException
259 259
 	 */
260
-	public function filterExists( $subject, $predicate = null, $object = null ) {
261
-		$this->graphBuilder->filterExists( $subject, $predicate, $object );
260
+	public function filterExists($subject, $predicate = null, $object = null) {
261
+		$this->graphBuilder->filterExists($subject, $predicate, $object);
262 262
 		return $this;
263 263
 	}
264 264
 
@@ -273,8 +273,8 @@  discard block
 block discarded – undo
273 273
 	 * @return self
274 274
 	 * @throws InvalidArgumentException
275 275
 	 */
276
-	public function filterNotExists( $subject, $predicate = null, $object = null ) {
277
-		$this->graphBuilder->filterNotExists( $subject, $predicate, $object );
276
+	public function filterNotExists($subject, $predicate = null, $object = null) {
277
+		$this->graphBuilder->filterNotExists($subject, $predicate, $object);
278 278
 		return $this;
279 279
 	}
280 280
 
@@ -287,8 +287,8 @@  discard block
 block discarded – undo
287 287
 	 * @return self
288 288
 	 * @throws InvalidArgumentException
289 289
 	 */
290
-	public function union( $graphs /* graphs ... */ ) {
291
-		call_user_func_array( array( $this->graphBuilder, 'union' ), func_get_args() );
290
+	public function union($graphs /* graphs ... */) {
291
+		call_user_func_array(array($this->graphBuilder, 'union'), func_get_args());
292 292
 		return $this;
293 293
 	}
294 294
 
@@ -299,8 +299,8 @@  discard block
 block discarded – undo
299 299
 	 * @return self
300 300
 	 * @throws InvalidArgumentException
301 301
 	 */
302
-	public function subquery( QueryBuilder $query ) {
303
-		$this->graphBuilder->subquery( $query );
302
+	public function subquery(QueryBuilder $query) {
303
+		$this->graphBuilder->subquery($query);
304 304
 		return $this;
305 305
 	}
306 306
 
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
 	 * @return QueryBuilder
311 311
 	 */
312 312
 	public function newSubquery() {
313
-		return new QueryBuilder( $this->prefixBuilder->getPrefixes() );
313
+		return new QueryBuilder($this->prefixBuilder->getPrefixes());
314 314
 	}
315 315
 
316 316
 	/**
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
 	 * @return GraphBuilder
322 322
 	 */
323 323
 	public function newSubgraph() {
324
-		return new GraphBuilder( $this->usageValidator );
324
+		return new GraphBuilder($this->usageValidator);
325 325
 	}
326 326
 
327 327
 	/**
@@ -331,10 +331,10 @@  discard block
 block discarded – undo
331 331
 	 * @return self
332 332
 	 * @throws InvalidArgumentException
333 333
 	 */
334
-	public function groupBy( $expressions /* expressions ... */ )  {
335
-		$expressions = is_array( $expressions ) ? $expressions : func_get_args();
334
+	public function groupBy($expressions /* expressions ... */) {
335
+		$expressions = is_array($expressions) ? $expressions : func_get_args();
336 336
 
337
-		$this->modifierBuilder->groupBy( $expressions );
337
+		$this->modifierBuilder->groupBy($expressions);
338 338
 		return $this;
339 339
 	}
340 340
 
@@ -345,8 +345,8 @@  discard block
 block discarded – undo
345 345
 	 * @return self
346 346
 	 * @throws InvalidArgumentException
347 347
 	 */
348
-	public function having( $expression ) {
349
-		$this->modifierBuilder->having( $expression );
348
+	public function having($expression) {
349
+		$this->modifierBuilder->having($expression);
350 350
 		return $this;
351 351
 	}
352 352
 
@@ -358,8 +358,8 @@  discard block
 block discarded – undo
358 358
 	 * @return self
359 359
 	 * @throws InvalidArgumentException
360 360
 	 */
361
-	public function orderBy( $expression, $direction = 'ASC' ) {
362
-		$this->modifierBuilder->orderBy( $expression, $direction );
361
+	public function orderBy($expression, $direction = 'ASC') {
362
+		$this->modifierBuilder->orderBy($expression, $direction);
363 363
 		return $this;
364 364
 	}
365 365
 
@@ -370,8 +370,8 @@  discard block
 block discarded – undo
370 370
 	 * @return self
371 371
 	 * @throws InvalidArgumentException
372 372
 	 */
373
-	public function limit( $limit ) {
374
-		$this->modifierBuilder->limit( $limit );
373
+	public function limit($limit) {
374
+		$this->modifierBuilder->limit($limit);
375 375
 		return $this;
376 376
 	}
377 377
 
@@ -382,8 +382,8 @@  discard block
 block discarded – undo
382 382
 	 * @return self
383 383
 	 * @throws InvalidArgumentException
384 384
 	 */
385
-	public function offset( $offset ) {
386
-		$this->modifierBuilder->offset( $offset );
385
+	public function offset($offset) {
386
+		$this->modifierBuilder->offset($offset);
387 387
 		return $this;
388 388
 	}
389 389
 
@@ -395,9 +395,9 @@  discard block
 block discarded – undo
395 395
 	 * @throws InvalidArgumentException
396 396
 	 * @throws RangeException
397 397
 	 */
398
-	public function getSPARQL( $includePrefixes = true ) {
399
-		if ( !is_bool( $includePrefixes ) ) {
400
-			throw new InvalidArgumentException( '$includePrefixes has to be a bool' );
398
+	public function getSPARQL($includePrefixes = true) {
399
+		if (!is_bool($includePrefixes)) {
400
+			throw new InvalidArgumentException('$includePrefixes has to be a bool');
401 401
 		}
402 402
 
403 403
 		$this->usageValidator->validate();
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
 	}
414 414
 
415 415
 	private function formatSelects() {
416
-		return empty( $this->selects ) ? '*' : implode( ' ', $this->selects );
416
+		return empty($this->selects) ? '*' : implode(' ', $this->selects);
417 417
 	}
418 418
 
419 419
 	/**
@@ -434,7 +434,7 @@  discard block
 block discarded – undo
434 434
 	 */
435 435
 	public function format() {
436 436
 		$formatter = new QueryFormatter();
437
-		return $formatter->format( $this->getSPARQL() );
437
+		return $formatter->format($this->getSPARQL());
438 438
 	}
439 439
 
440 440
 }
Please login to merge, or discard this patch.
src/QueryExecuter.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -68,6 +68,9 @@
 block discarded – undo
68 68
 		return $result['results'];
69 69
 	}
70 70
 
71
+	/**
72
+	 * @param string $query
73
+	 */
71 74
 	private function getResult( $query ) {
72 75
 		$result = $this->http->request( $this->url, array(
73 76
 			$this->options['queryParam'] => $query,
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -36,14 +36,14 @@  discard block
 block discarded – undo
36 36
 	 * @param string[] $options one of queryParam, formatParam or userAgent
37 37
 	 * @param Http|null $http
38 38
 	 */
39
-	public function __construct( $url, array $options = array(), Http $http = null ) {
39
+	public function __construct($url, array $options = array(), Http $http = null) {
40 40
 		$this->url = $url;
41
-		$this->options = array_merge( array(
41
+		$this->options = array_merge(array(
42 42
 			'queryParam' => 'query',
43 43
 			'formatParam' => 'format',
44 44
 			'userAgent' => 'Asparagus/Asparagus 0.1'
45
-		), $options );
46
-		$this->http = $http ?: new Http( $this->options['userAgent'] );
45
+		), $options);
46
+		$this->http = $http ?: new Http($this->options['userAgent']);
47 47
 	}
48 48
 
49 49
 	/**
@@ -55,26 +55,26 @@  discard block
 block discarded – undo
55 55
 	 * @throws RangeException
56 56
 	 * @throws RuntimeException
57 57
 	 */
58
-	public function execute( $query ) {
59
-		if ( $query instanceof QueryBuilder ) {
58
+	public function execute($query) {
59
+		if ($query instanceof QueryBuilder) {
60 60
 			$query = $query->getSPARQL();
61 61
 		}
62 62
 
63
-		if ( !is_string( $query ) ) {
64
-			throw new InvalidArgumentException( '$query has to be a string or an instance of QueryBuilder' );
63
+		if (!is_string($query)) {
64
+			throw new InvalidArgumentException('$query has to be a string or an instance of QueryBuilder');
65 65
 		}
66 66
 
67
-		$result = $this->getResult( $query );
67
+		$result = $this->getResult($query);
68 68
 		return $result['results'];
69 69
 	}
70 70
 
71
-	private function getResult( $query ) {
72
-		$result = $this->http->request( $this->url, array(
71
+	private function getResult($query) {
72
+		$result = $this->http->request($this->url, array(
73 73
 			$this->options['queryParam'] => $query,
74 74
 			$this->options['formatParam'] => 'json'
75
-		) );
75
+		));
76 76
 
77
-		return json_decode( $result, true );
77
+		return json_decode($result, true);
78 78
 	}
79 79
 
80 80
 }
Please login to merge, or discard this patch.
src/QueryFormatter.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -58,6 +58,9 @@
 block discarded – undo
58 58
 		return strtr( implode( $this->formattedParts ), $this->replacements );
59 59
 	}
60 60
 
61
+	/**
62
+	 * @param string $string
63
+	 */
61 64
 	private function split( $string ) {
62 65
 		return preg_split(
63 66
 			'/(\W)/',
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -34,31 +34,31 @@  discard block
 block discarded – undo
34 34
 	 * @param string $sparql
35 35
 	 * @return string
36 36
 	 */
37
-	public function format( $sparql ) {
37
+	public function format($sparql) {
38 38
 		$this->formattedParts = array();
39 39
 		$this->indentationLevel = 0;
40 40
 		$this->replacements = array();
41 41
 
42 42
 		$regexHelper = new RegexHelper();
43
-		$sparql = $regexHelper->escapeSequences( $sparql, $this->replacements );
43
+		$sparql = $regexHelper->escapeSequences($sparql, $this->replacements);
44 44
 
45
-		foreach ( $this->split( $sparql ) as $part ) {
46
-			if ( !empty( $this->formattedParts ) ) {
47
-				$this->before( $part );
45
+		foreach ($this->split($sparql) as $part) {
46
+			if (!empty($this->formattedParts)) {
47
+				$this->before($part);
48 48
 			}
49 49
 
50
-			$this->indentation( $part );
51
-			$this->append( $part );
52
-			$this->after( $part );
50
+			$this->indentation($part);
51
+			$this->append($part);
52
+			$this->after($part);
53 53
 		}
54 54
 
55 55
 		$this->trimEnd();
56 56
 		$this->formattedParts[] = "\n";
57 57
 
58
-		return strtr( implode( $this->formattedParts ), $this->replacements );
58
+		return strtr(implode($this->formattedParts), $this->replacements);
59 59
 	}
60 60
 
61
-	private function split( $string ) {
61
+	private function split($string) {
62 62
 		return preg_split(
63 63
 			'/(\W)/',
64 64
 			$string,
@@ -67,64 +67,64 @@  discard block
 block discarded – undo
67 67
 		);
68 68
 	}
69 69
 
70
-	private function before( $part ) {
71
-		if ( in_array( $part, array( 'PREFIX', 'FILTER', 'OPTIONAL', 'LIMIT', 'GROUP', 'ORDER', 'HAVING', '}' ) ) ) {
70
+	private function before($part) {
71
+		if (in_array($part, array('PREFIX', 'FILTER', 'OPTIONAL', 'LIMIT', 'GROUP', 'ORDER', 'HAVING', '}'))) {
72 72
 			$this->trimEnd();
73 73
 			$this->formattedParts[] = "\n";
74 74
 		}
75 75
 
76
-		if ( $part === 'SELECT' && $this->indentationLevel === 0 ) {
76
+		if ($part === 'SELECT' && $this->indentationLevel === 0) {
77 77
 			$this->trimEnd();
78 78
 			$this->formattedParts[] = "\n\n";
79 79
 		}
80 80
 
81 81
 		// UNION is the only part we want to have in-line with "}", ie. } UNION {
82
-		if ( $part === 'UNION' || end( $this->formattedParts ) !== "\n" &&
83
-			in_array( $part, array( '.', '=', '(', '<', '{', '?', '$' ) )
82
+		if ($part === 'UNION' || end($this->formattedParts) !== "\n" &&
83
+			in_array($part, array('.', '=', '(', '<', '{', '?', '$'))
84 84
 		) {
85 85
 			$this->trimEnd();
86
-			$this->append( ' ' );
86
+			$this->append(' ');
87 87
 		}
88 88
 	}
89 89
 
90
-	private function indentation( $part ) {
91
-		if ( $part === '}' ) {
90
+	private function indentation($part) {
91
+		if ($part === '}') {
92 92
 			$this->indentationLevel--;
93 93
 		}
94 94
 
95
-		if ( !ctype_space( $part ) && substr( end( $this->formattedParts ), 0, 1 ) === "\n" ) {
96
-			$this->formattedParts[] = str_repeat( "\t", $this->indentationLevel );
95
+		if (!ctype_space($part) && substr(end($this->formattedParts), 0, 1) === "\n") {
96
+			$this->formattedParts[] = str_repeat("\t", $this->indentationLevel);
97 97
 		}
98 98
 
99
-		if ( $part === '{' ) {
99
+		if ($part === '{') {
100 100
 			$this->indentationLevel++;
101 101
 		}
102 102
 	}
103 103
 
104
-	private function append( $part ) {
105
-		if ( !ctype_space( $part ) ) {
104
+	private function append($part) {
105
+		if (!ctype_space($part)) {
106 106
 			$this->formattedParts[] = $part;
107 107
 		} else if ( // ctype_space( $part ) &&
108
-			!ctype_space( end( $this->formattedParts ) ) &&
109
-			end( $this->formattedParts ) !== '('
108
+			!ctype_space(end($this->formattedParts)) &&
109
+			end($this->formattedParts) !== '('
110 110
 		) {
111 111
 			$this->formattedParts[] = ' ';
112 112
 		}
113 113
 	}
114 114
 
115
-	private function after( $part ) {
116
-		if ( in_array( $part, array( '{', '}', '.' ) ) ) {
115
+	private function after($part) {
116
+		if (in_array($part, array('{', '}', '.'))) {
117 117
 			$this->formattedParts[] = "\n";
118 118
 		}
119 119
 
120
-		if ( $part === ';' ) {
120
+		if ($part === ';') {
121 121
 			$this->formattedParts[] = "\n\t";
122 122
 		}
123 123
 	}
124 124
 
125 125
 	private function trimEnd() {
126
-		while ( ctype_space( end( $this->formattedParts ) ) ) {
127
-			array_pop( $this->formattedParts );
126
+		while (ctype_space(end($this->formattedParts))) {
127
+			array_pop($this->formattedParts);
128 128
 		}
129 129
 	}
130 130
 
Please login to merge, or discard this patch.
src/UsageValidator.php 2 patches
Doc Comments   +6 added lines patch added patch discarded remove patch
@@ -93,10 +93,16 @@
 block discarded – undo
93 93
 		$this->definedPrefixes = array_merge( $this->definedPrefixes, $prefixes );
94 94
 	}
95 95
 
96
+	/**
97
+	 * @param string $expression
98
+	 */
96 99
 	private function matchVariables( $expression ) {
97 100
 		return $this->regexHelper->getMatches( '(^|\W)(?<!AS )\{variable}', $expression, 2 );
98 101
 	}
99 102
 
103
+	/**
104
+	 * @param string $expression
105
+	 */
100 106
 	private function matchPrefixes( $expression ) {
101 107
 		return $this->regexHelper->getMatches( '(^|\W)(\{prefix}):\{name}', $expression, 2 );
102 108
 	}
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -46,12 +46,12 @@  discard block
 block discarded – undo
46 46
 	 *
47 47
 	 * @param string[]|string $variables list of variables without prefixes
48 48
 	 */
49
-	public function trackUsedVariables( $variables ) {
50
-		if ( !is_array( $variables ) ) {
51
-			$variables = $this->matchVariables( $variables );
49
+	public function trackUsedVariables($variables) {
50
+		if (!is_array($variables)) {
51
+			$variables = $this->matchVariables($variables);
52 52
 		}
53 53
 
54
-		$this->usedVariables = array_unique( array_merge( $this->usedVariables, $variables ) );
54
+		$this->usedVariables = array_unique(array_merge($this->usedVariables, $variables));
55 55
 	}
56 56
 
57 57
 	/**
@@ -59,12 +59,12 @@  discard block
 block discarded – undo
59 59
 	 *
60 60
 	 * @param string[]|string $variables list of variables without prefixes
61 61
 	 */
62
-	public function trackDefinedVariables( $variables )  {
63
-		if ( !is_array( $variables ) ) {
64
-			$variables = $this->matchVariables( $variables );
62
+	public function trackDefinedVariables($variables) {
63
+		if (!is_array($variables)) {
64
+			$variables = $this->matchVariables($variables);
65 65
 		}
66 66
 
67
-		$this->definedVariables = array_unique( array_merge( $this->definedVariables, $variables ) );
67
+		$this->definedVariables = array_unique(array_merge($this->definedVariables, $variables));
68 68
 	}
69 69
 
70 70
 	/**
@@ -72,12 +72,12 @@  discard block
 block discarded – undo
72 72
 	 *
73 73
 	 * @param string[]|string $prefixes list of prefixes
74 74
 	 */
75
-	public function trackUsedPrefixes( $prefixes )  {
76
-		if ( !is_array( $prefixes ) ) {
77
-			$prefixes = $this->matchPrefixes( $prefixes );
75
+	public function trackUsedPrefixes($prefixes) {
76
+		if (!is_array($prefixes)) {
77
+			$prefixes = $this->matchPrefixes($prefixes);
78 78
 		}
79 79
 
80
-		$this->usedPrefixes = array_merge( $this->usedPrefixes, $prefixes );
80
+		$this->usedPrefixes = array_merge($this->usedPrefixes, $prefixes);
81 81
 	}
82 82
 
83 83
 	/**
@@ -85,20 +85,20 @@  discard block
 block discarded – undo
85 85
 	 *
86 86
 	 * @param string[]|string $prefixes list of prefixes
87 87
 	 */
88
-	public function trackDefinedPrefixes( $prefixes )  {
89
-		if ( !is_array( $prefixes ) ) {
90
-			$prefixes = $this->matchPrefixes( $prefixes );
88
+	public function trackDefinedPrefixes($prefixes) {
89
+		if (!is_array($prefixes)) {
90
+			$prefixes = $this->matchPrefixes($prefixes);
91 91
 		}
92 92
 
93
-		$this->definedPrefixes = array_merge( $this->definedPrefixes, $prefixes );
93
+		$this->definedPrefixes = array_merge($this->definedPrefixes, $prefixes);
94 94
 	}
95 95
 
96
-	private function matchVariables( $expression ) {
97
-		return $this->regexHelper->getMatches( '(^|\W)(?<!AS )\{variable}', $expression, 2 );
96
+	private function matchVariables($expression) {
97
+		return $this->regexHelper->getMatches('(^|\W)(?<!AS )\{variable}', $expression, 2);
98 98
 	}
99 99
 
100
-	private function matchPrefixes( $expression ) {
101
-		return $this->regexHelper->getMatches( '(^|\W)(\{prefix}):\{name}', $expression, 2 );
100
+	private function matchPrefixes($expression) {
101
+		return $this->regexHelper->getMatches('(^|\W)(\{prefix}):\{name}', $expression, 2);
102 102
 	}
103 103
 
104 104
 	/**
@@ -112,16 +112,16 @@  discard block
 block discarded – undo
112 112
 	}
113 113
 
114 114
 	private function validatePrefixes() {
115
-		$diff = array_diff( $this->usedPrefixes, $this->definedPrefixes );
116
-		if ( !empty( $diff ) ) {
117
-			throw new RangeException( 'The prefixes ' . implode( ', ', $diff ) . ' aren\'t defined for this query.' );
115
+		$diff = array_diff($this->usedPrefixes, $this->definedPrefixes);
116
+		if (!empty($diff)) {
117
+			throw new RangeException('The prefixes ' . implode(', ', $diff) . ' aren\'t defined for this query.');
118 118
 		}
119 119
 	}
120 120
 
121 121
 	private function validateVariables() {
122
-		$diff = array_diff( $this->usedVariables, $this->definedVariables );
123
-		if ( !empty( $diff ) ) {
124
-			throw new RangeException( 'The variables ?' . implode( ', ?', $diff ) . ' don\'t occur in this query.' );
122
+		$diff = array_diff($this->usedVariables, $this->definedVariables);
123
+		if (!empty($diff)) {
124
+			throw new RangeException('The variables ?' . implode(', ?', $diff) . ' don\'t occur in this query.');
125 125
 		}
126 126
 	}
127 127
 
Please login to merge, or discard this patch.
tests/integration/QueryBuilderTest.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -15,71 +15,71 @@
 block discarded – undo
15 15
 	);
16 16
 
17 17
 	public function testBasicFunctionality() {
18
-		$queryBuilder = new QueryBuilder( self::$prefixes );
18
+		$queryBuilder = new QueryBuilder(self::$prefixes);
19 19
 
20
-		$queryBuilder->select( '?name', '?email' )
21
-			->where( '?person', 'test:name', '?name' )
22
-			->also( 'test:email', '?email' )
23
-			->limit( 10 );
20
+		$queryBuilder->select('?name', '?email')
21
+			->where('?person', 'test:name', '?name')
22
+			->also('test:email', '?email')
23
+			->limit(10);
24 24
 
25
-		$this->assertIsExpected( 'basic_functionality', $queryBuilder->format() );
25
+		$this->assertIsExpected('basic_functionality', $queryBuilder->format());
26 26
 	}
27 27
 
28 28
 	public function testOptionalFilter() {
29
-		$queryBuilder = new QueryBuilder( self::$prefixes );
30
-		$queryBuilder->select( '?name' )
31
-			->where( '?person', 'test:name', '?name' )
32
-			->optional( '?person', 'test:email', '?email' )
33
-			->filter( '!BOUND (?email)' );
29
+		$queryBuilder = new QueryBuilder(self::$prefixes);
30
+		$queryBuilder->select('?name')
31
+			->where('?person', 'test:name', '?name')
32
+			->optional('?person', 'test:email', '?email')
33
+			->filter('!BOUND (?email)');
34 34
 
35
-		$this->assertIsExpected( 'optional_filter', $queryBuilder->format() );
35
+		$this->assertIsExpected('optional_filter', $queryBuilder->format());
36 36
 	}
37 37
 
38 38
 	public function testUnion() {
39
-		$queryBuilder = new QueryBuilder( array(
39
+		$queryBuilder = new QueryBuilder(array(
40 40
 			'dc10' => 'http://purl.org/dc/elements/1.0/',
41 41
 			'dc11' => 'http://purl.org/dc/elements/1.1/'
42
-		) );
42
+		));
43 43
 
44
-		$queryBuilder->select( '?title', '?author' )
44
+		$queryBuilder->select('?title', '?author')
45 45
 			->union(
46 46
 				$queryBuilder->newSubgraph()
47
-					->where( '?book', 'dc10:title', '?title' )
48
-					->also( 'dc10:creator', '?author' ),
47
+					->where('?book', 'dc10:title', '?title')
48
+					->also('dc10:creator', '?author'),
49 49
 				$queryBuilder->newSubgraph()
50
-					->where( '?book', 'dc11:title', '?title' )
51
-					->also( 'dc11:creator', '?author' )
50
+					->where('?book', 'dc11:title', '?title')
51
+					->also('dc11:creator', '?author')
52 52
 			);
53 53
 
54
-		$this->assertIsExpected( 'union', $queryBuilder->format() );
54
+		$this->assertIsExpected('union', $queryBuilder->format());
55 55
 	}
56 56
 
57 57
 	public function testUndefinedPrefixDetected() {
58
-		$queryBuilder = new QueryBuilder( self::$prefixes );
58
+		$queryBuilder = new QueryBuilder(self::$prefixes);
59 59
 
60
-		$queryBuilder->select( '?age' )
61
-			->where( '?person', 'test:name', '?name' )
62
-			->also( 'nyan:age', '?age' );
60
+		$queryBuilder->select('?age')
61
+			->where('?person', 'test:name', '?name')
62
+			->also('nyan:age', '?age');
63 63
 
64
-		$this->setExpectedException( 'RangeException', 'nyan' );
64
+		$this->setExpectedException('RangeException', 'nyan');
65 65
 		$queryBuilder->getSPARQL();
66 66
 	}
67 67
 
68 68
 	public function testUndefinedVariableDetected() {
69
-		$queryBuilder = new QueryBuilder( self::$prefixes );
69
+		$queryBuilder = new QueryBuilder(self::$prefixes);
70 70
 
71
-		$queryBuilder->select( '?email' )
72
-			->where( '?person', 'test:name', '?name' )
73
-			->also( 'test:age', '?age' );
71
+		$queryBuilder->select('?email')
72
+			->where('?person', 'test:name', '?name')
73
+			->also('test:age', '?age');
74 74
 
75
-		$this->setExpectedException( 'RangeException', '?email' );
75
+		$this->setExpectedException('RangeException', '?email');
76 76
 		$queryBuilder->getSPARQL();
77 77
 	}
78 78
 
79
-	private function assertIsExpected( $name, $sparql ) {
80
-		$expected = file_get_contents( __DIR__ . '/../data/builder_' . $name . '.rq' );
79
+	private function assertIsExpected($name, $sparql) {
80
+		$expected = file_get_contents(__DIR__ . '/../data/builder_' . $name . '.rq');
81 81
 
82
-		$this->assertEquals( $expected, $sparql, 'Query didn\'t match the expected content of integration_' . $name . '.rq' );
82
+		$this->assertEquals($expected, $sparql, 'Query didn\'t match the expected content of integration_' . $name . '.rq');
83 83
 	}
84 84
 
85 85
 }
Please login to merge, or discard this patch.
tests/integration/WDQSQueryExamplesTest.php 1 patch
Spacing   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -22,245 +22,245 @@
 block discarded – undo
22 22
 	);
23 23
 
24 24
 	public function testUSPresidentsAndSpouses() {
25
-		$queryBuilder = new QueryBuilder( self::$prefixes );
25
+		$queryBuilder = new QueryBuilder(self::$prefixes);
26 26
 
27
-		$queryBuilder->select( '?p', '?w', '?l', '?wl' )
28
-			->where( 'wd:Q30', 'p:P6/v:P6', '?p' )
29
-			->where( '?p', 'wdt:P26', '?w' )
27
+		$queryBuilder->select('?p', '?w', '?l', '?wl')
28
+			->where('wd:Q30', 'p:P6/v:P6', '?p')
29
+			->where('?p', 'wdt:P26', '?w')
30 30
 			->optional(
31 31
 				$queryBuilder->newSubgraph()
32
-					->where( '?p', 'rdfs:label', '?l' )
33
-					->filter( 'LANG(?l) = "en"' )
32
+					->where('?p', 'rdfs:label', '?l')
33
+					->filter('LANG(?l) = "en"')
34 34
 			)
35 35
 			->optional(
36 36
 				$queryBuilder->newSubgraph()
37
-					->where( '?w', 'rdfs:label', '?wl' )
38
-					->filter( 'LANG(?wl) = "en"' )
37
+					->where('?w', 'rdfs:label', '?wl')
38
+					->filter('LANG(?wl) = "en"')
39 39
 			);
40 40
 
41
-		$this->assertIsExpected( 'US_presidents_and_spouses', $queryBuilder->format() );
41
+		$this->assertIsExpected('US_presidents_and_spouses', $queryBuilder->format());
42 42
 	}
43 43
 
44 44
 	public function testPresidentsAndCausesOfDeath() {
45
-		$queryBuilder = new QueryBuilder( self::$prefixes );
45
+		$queryBuilder = new QueryBuilder(self::$prefixes);
46 46
 
47
-		$queryBuilder->select( '?h', '?cause', '?hl', '?causel' )
48
-			->where( '?h', 'wdt:P39', 'wd:Q11696' )
49
-			->also( 'wdt:P509', '?cause' )
47
+		$queryBuilder->select('?h', '?cause', '?hl', '?causel')
48
+			->where('?h', 'wdt:P39', 'wd:Q11696')
49
+			->also('wdt:P509', '?cause')
50 50
 			->optional(
51 51
 				$queryBuilder->newSubgraph()
52
-					->where( '?h', 'rdfs:label', '?hl' )
53
-					->filter( 'LANG(?hl) = "en"' )
52
+					->where('?h', 'rdfs:label', '?hl')
53
+					->filter('LANG(?hl) = "en"')
54 54
 			)
55 55
 			->optional(
56 56
 				$queryBuilder->newSubgraph()
57
-					->where( '?cause', 'rdfs:label', '?causel' )
58
-					->filter( 'LANG(?causel) = "en"' )
57
+					->where('?cause', 'rdfs:label', '?causel')
58
+					->filter('LANG(?causel) = "en"')
59 59
 			);
60 60
 
61
-		$this->assertIsExpected( 'Presidents_and_causes_of_death', $queryBuilder->format() );
61
+		$this->assertIsExpected('Presidents_and_causes_of_death', $queryBuilder->format());
62 62
 	}
63 63
 
64 64
 	public function testPeopleBornBeforeYear1880WithNoDeathDate() {
65
-		$queryBuilder = new QueryBuilder( self::$prefixes );
65
+		$queryBuilder = new QueryBuilder(self::$prefixes);
66 66
 
67
-		$queryBuilder->select( '?h', '?date' )
68
-			->where( '?h', 'wdt:P31', 'wd:Q5' )
69
-			->also( 'wdt:P569', '?date' )
70
-			->optional( '?h', 'wdt:P570', '?d' )
71
-			->filter( '?date < "1880-01-01T00:00:00Z"^^xsd:dateTime' )
72
-			->filter( '!BOUND(?d)' )
73
-			->limit( 100 );
67
+		$queryBuilder->select('?h', '?date')
68
+			->where('?h', 'wdt:P31', 'wd:Q5')
69
+			->also('wdt:P569', '?date')
70
+			->optional('?h', 'wdt:P570', '?d')
71
+			->filter('?date < "1880-01-01T00:00:00Z"^^xsd:dateTime')
72
+			->filter('!BOUND(?d)')
73
+			->limit(100);
74 74
 
75
-		$this->assertIsExpected( 'People_born_before_year_1880_with_no_death_date', $queryBuilder->format() );
75
+		$this->assertIsExpected('People_born_before_year_1880_with_no_death_date', $queryBuilder->format());
76 76
 	}
77 77
 
78 78
 	public function testLargestCitiesWithFemaleMayor() {
79
-		$queryBuilder = new QueryBuilder( self::$prefixes );
80
-
81
-		$queryBuilder->selectDistinct( '?city', '?citylabel', '?mayorlabel' )
82
-			->where( '?city', 'wdt:P31/wdt:P279*', 'wd:Q515' )
83
-			->also( 'p:P6', '?statement' )
84
-			->also( 'wdt:P1082', '?population' )
85
-			->where( '?statement', 'v:P6', '?mayor' )
86
-			->where( '?mayor', 'wdt:P21', 'wd:Q6581072' )
87
-			->filterNotExists( '?statement', 'q:P582', '?x' )
79
+		$queryBuilder = new QueryBuilder(self::$prefixes);
80
+
81
+		$queryBuilder->selectDistinct('?city', '?citylabel', '?mayorlabel')
82
+			->where('?city', 'wdt:P31/wdt:P279*', 'wd:Q515')
83
+			->also('p:P6', '?statement')
84
+			->also('wdt:P1082', '?population')
85
+			->where('?statement', 'v:P6', '?mayor')
86
+			->where('?mayor', 'wdt:P21', 'wd:Q6581072')
87
+			->filterNotExists('?statement', 'q:P582', '?x')
88 88
 			->optional(
89 89
 				$queryBuilder->newSubgraph()
90
-					->where( '?city', 'rdfs:label', '?citylabel' )
91
-					->filter( 'LANG(?citylabel) = "en"' )
90
+					->where('?city', 'rdfs:label', '?citylabel')
91
+					->filter('LANG(?citylabel) = "en"')
92 92
 			)
93 93
 			->optional(
94 94
 				$queryBuilder->newSubgraph()
95
-					->where( '?mayor', 'rdfs:label', '?mayorlabel' )
96
-					->filter( 'LANG(?mayorlabel) = "en"' )
95
+					->where('?mayor', 'rdfs:label', '?mayorlabel')
96
+					->filter('LANG(?mayorlabel) = "en"')
97 97
 			)
98
-			->orderBy( '?population', 'DESC' )
99
-			->limit( 10 );
98
+			->orderBy('?population', 'DESC')
99
+			->limit(10);
100 100
 
101
-		$this->assertIsExpected( 'Largest_cities_with_female_mayor', $queryBuilder->format() );
101
+		$this->assertIsExpected('Largest_cities_with_female_mayor', $queryBuilder->format());
102 102
 	}
103 103
 
104 104
 	public function testListOfCountriesOrderedByTheNumberOfTheirCitiesWithFemaleMayor() {
105
-		$queryBuilder = new QueryBuilder( self::$prefixes );
106
-
107
-		$queryBuilder->select( '?country', '?label', '(COUNT(*) AS ?COUNT)' )
108
-			->where( '?city', 'wdt:P31/wdt:P279*', 'wd:Q515' )
109
-			->also( 'p:P6', '?statement' )
110
-			->also( 'wdt:P17', '?country' )
111
-			->where( '?statement', 'v:P6', '?mayor' )
112
-			->where( '?mayor', 'wdt:P21', 'wd:Q6581072' )
113
-			->filterNotExists( '?statement', 'q:P582', '?x' )
105
+		$queryBuilder = new QueryBuilder(self::$prefixes);
106
+
107
+		$queryBuilder->select('?country', '?label', '(COUNT(*) AS ?COUNT)')
108
+			->where('?city', 'wdt:P31/wdt:P279*', 'wd:Q515')
109
+			->also('p:P6', '?statement')
110
+			->also('wdt:P17', '?country')
111
+			->where('?statement', 'v:P6', '?mayor')
112
+			->where('?mayor', 'wdt:P21', 'wd:Q6581072')
113
+			->filterNotExists('?statement', 'q:P582', '?x')
114 114
 			->optional(
115 115
 				$queryBuilder->newSubgraph()
116
-					->where( '?country', 'rdfs:label', '?label' )
117
-					->filter( 'LANG(?label) = "en"' )
116
+					->where('?country', 'rdfs:label', '?label')
117
+					->filter('LANG(?label) = "en"')
118 118
 			)
119
-			->groupBy( '?country', '?label' )
120
-			->orderBy( '?COUNT', 'DESC' )
121
-			->limit( 100 );
119
+			->groupBy('?country', '?label')
120
+			->orderBy('?COUNT', 'DESC')
121
+			->limit(100);
122 122
 
123
-		$this->assertIsExpected( 'List_of_countries_ordered_by_the_number_of_their_cities_with_female_mayor', $queryBuilder->format() );
123
+		$this->assertIsExpected('List_of_countries_ordered_by_the_number_of_their_cities_with_female_mayor', $queryBuilder->format());
124 124
 	}
125 125
 
126 126
 	public function testsHowManyStatesThisUSStateBorders() {
127
-		$queryBuilder = new QueryBuilder( self::$prefixes );
127
+		$queryBuilder = new QueryBuilder(self::$prefixes);
128 128
 
129
-		$queryBuilder->select( '?state', '?stateL', '?borders' )
129
+		$queryBuilder->select('?state', '?stateL', '?borders')
130 130
 			->subquery(
131 131
 				$queryBuilder->newSubquery()
132
-					->select( '?state', '(COUNT (?otherState) AS ?borders)' )
133
-					->where( '?state', 'wdt:P31', 'wd:Q35657' )
134
-					->where( '?otherState', 'wdt:P47', '?state' )
135
-					->also( 'wdt:P31', 'wd:Q35657' )
136
-					->groupBy( '?state' )
132
+					->select('?state', '(COUNT (?otherState) AS ?borders)')
133
+					->where('?state', 'wdt:P31', 'wd:Q35657')
134
+					->where('?otherState', 'wdt:P47', '?state')
135
+					->also('wdt:P31', 'wd:Q35657')
136
+					->groupBy('?state')
137 137
 			)
138 138
 			->optional(
139 139
 				$queryBuilder->newSubgraph()
140
-					->where( '?state', 'rdfs:label', '?stateL' )
141
-					->filter( 'LANG(?stateL) = "en"' )
140
+					->where('?state', 'rdfs:label', '?stateL')
141
+					->filter('LANG(?stateL) = "en"')
142 142
 			)
143
-			->orderBy( '?borders', 'DESC' );
143
+			->orderBy('?borders', 'DESC');
144 144
 
145
-		$this->assertIsExpected( 'How_many_states_this_US_state_borders', $queryBuilder->format() );
145
+		$this->assertIsExpected('How_many_states_this_US_state_borders', $queryBuilder->format());
146 146
 	}
147 147
 
148 148
 	public function testWhoseBirthdayIsToday() {
149
-		$queryBuilder = new QueryBuilder( self::$prefixes );
149
+		$queryBuilder = new QueryBuilder(self::$prefixes);
150 150
 
151
-		$queryBuilder->select( '?entity', '(YEAR(?date) AS ?YEAR)' )
152
-			->where( '?entityS', 'wdt:P569', '?date' )
153
-			->also( 'rdfs:label', '?entity' )
154
-			->filter( 'DATATYPE (?date) = xsd:dateTime' )
155
-			->filter( 'MONTH (?date) = MONTH (NOW ())' )
156
-			->filter( 'DAY (?date) = DAY (NOW ())' )
157
-			->limit( 10 );
151
+		$queryBuilder->select('?entity', '(YEAR(?date) AS ?YEAR)')
152
+			->where('?entityS', 'wdt:P569', '?date')
153
+			->also('rdfs:label', '?entity')
154
+			->filter('DATATYPE (?date) = xsd:dateTime')
155
+			->filter('MONTH (?date) = MONTH (NOW ())')
156
+			->filter('DAY (?date) = DAY (NOW ())')
157
+			->limit(10);
158 158
 
159
-		$this->assertIsExpected( 'Whose_birthday_is_today', $queryBuilder->format() );
159
+		$this->assertIsExpected('Whose_birthday_is_today', $queryBuilder->format());
160 160
 	}
161 161
 
162 162
 	public function testWhoDiscoveredTheMostAsteroids() {
163
-		$queryBuilder = new QueryBuilder( self::$prefixes );
163
+		$queryBuilder = new QueryBuilder(self::$prefixes);
164 164
 
165
-		$queryBuilder->select( '?discoverer', '?name', '(COUNT (?asteroid) AS ?count)' )
166
-			->where( '?asteroid', 'wdt:P31', 'wd:Q3863' )
167
-			->also( 'wdt:P61', '?discoverer' )
165
+		$queryBuilder->select('?discoverer', '?name', '(COUNT (?asteroid) AS ?count)')
166
+			->where('?asteroid', 'wdt:P31', 'wd:Q3863')
167
+			->also('wdt:P61', '?discoverer')
168 168
 			->optional(
169 169
 				$queryBuilder->newSubgraph()
170
-					->where( '?discoverer', 'rdfs:label', '?name' )
171
-					->filter( 'LANG(?name) = "en"' )
170
+					->where('?discoverer', 'rdfs:label', '?name')
171
+					->filter('LANG(?name) = "en"')
172 172
 			)
173
-			->groupBy( '?discoverer', '?name' )
174
-			->orderBy( '?count', 'DESC' )
175
-			->limit( 10 );
173
+			->groupBy('?discoverer', '?name')
174
+			->orderBy('?count', 'DESC')
175
+			->limit(10);
176 176
 
177
-		$this->assertIsExpected( 'Who_discovered_the_most_asteroids', $queryBuilder->format() );
177
+		$this->assertIsExpected('Who_discovered_the_most_asteroids', $queryBuilder->format());
178 178
 	}
179 179
 
180 180
 	public function testWhoDiscoveredTheMostPlanets() {
181
-		$queryBuilder = new QueryBuilder( self::$prefixes );
181
+		$queryBuilder = new QueryBuilder(self::$prefixes);
182 182
 
183
-		$queryBuilder->select( '?discoverer', '?name', '(COUNT (DISTINCT ?planet) AS ?count)' )
184
-			->where( '?ppart', 'wdt:P279*', 'wd:Q634' )
185
-			->where( '?planet', 'wdt:P31', '?ppart' )
186
-			->also( 'wdt:P61', '?discoverer' )
183
+		$queryBuilder->select('?discoverer', '?name', '(COUNT (DISTINCT ?planet) AS ?count)')
184
+			->where('?ppart', 'wdt:P279*', 'wd:Q634')
185
+			->where('?planet', 'wdt:P31', '?ppart')
186
+			->also('wdt:P61', '?discoverer')
187 187
 			->optional(
188 188
 				$queryBuilder->newSubgraph()
189
-					->where( '?discoverer', 'rdfs:label', '?name' )
190
-					->filter( 'LANG(?name) = "en"' )
189
+					->where('?discoverer', 'rdfs:label', '?name')
190
+					->filter('LANG(?name) = "en"')
191 191
 			)
192
-			->groupBy( '?discoverer', '?name' )
193
-			->orderBy( '?count', 'DESC' )
194
-			->limit( 10 );
192
+			->groupBy('?discoverer', '?name')
193
+			->orderBy('?count', 'DESC')
194
+			->limit(10);
195 195
 
196
-		$this->assertIsExpected( 'Who_discovered_the_most_planets', $queryBuilder->format() );
196
+		$this->assertIsExpected('Who_discovered_the_most_planets', $queryBuilder->format());
197 197
 	}
198 198
 
199 199
 	public function testAmericanUniversitiesFoundedBeforeTheStatesTheyResideInWereCreated() {
200
-		$queryBuilder = new QueryBuilder( self::$prefixes );
201
-
202
-		$queryBuilder->select( '?uniName', '?founded', '?stateName', '?stateStart' )
203
-			->where( '?uni', 'wdt:P31|wdt:P279/wdt:P31', 'wd:Q3918' )
204
-			->also( 'wdt:P131+', '?state' )
205
-			->also( 'wdt:P571', '?founded' )
206
-			->where( '?state', 'wdt:P31', 'wd:Q35657' )
207
-			->also( 'wdt:P571', '?stateStart' )
208
-			->filter( '?founded < ?stateStart' )
200
+		$queryBuilder = new QueryBuilder(self::$prefixes);
201
+
202
+		$queryBuilder->select('?uniName', '?founded', '?stateName', '?stateStart')
203
+			->where('?uni', 'wdt:P31|wdt:P279/wdt:P31', 'wd:Q3918')
204
+			->also('wdt:P131+', '?state')
205
+			->also('wdt:P571', '?founded')
206
+			->where('?state', 'wdt:P31', 'wd:Q35657')
207
+			->also('wdt:P571', '?stateStart')
208
+			->filter('?founded < ?stateStart')
209 209
 			->optional(
210 210
 				$queryBuilder->newSubgraph()
211
-					->where( '?state', 'rdfs:label', '?stateName' )
212
-					->filter( 'LANG(?stateName) = "en"' )
211
+					->where('?state', 'rdfs:label', '?stateName')
212
+					->filter('LANG(?stateName) = "en"')
213 213
 			)
214 214
 			->optional(
215 215
 				$queryBuilder->newSubgraph()
216
-					->where( '?uni', 'rdfs:label', '?uniName' )
217
-					->filter( 'LANG(?uniName) = "en"' )
216
+					->where('?uni', 'rdfs:label', '?uniName')
217
+					->filter('LANG(?uniName) = "en"')
218 218
 			)
219
-			->limit( 10 );
219
+			->limit(10);
220 220
 
221
-		$this->assertIsExpected( 'American_universities_founded_before_the_states_they_reside_in_were_created', $queryBuilder->format() );
221
+		$this->assertIsExpected('American_universities_founded_before_the_states_they_reside_in_were_created', $queryBuilder->format());
222 222
 	}
223 223
 
224 224
 	public function testWhatIsTheRelationBetweenTerrellBuckleyAndMiamiDolphins() {
225
-		$queryBuilder = new QueryBuilder( self::$prefixes );
225
+		$queryBuilder = new QueryBuilder(self::$prefixes);
226 226
 
227
-		$queryBuilder->select( '?l' )
228
-			->where( 'wd:Q5571382', '?p', 'wd:Q223243' )
229
-			->where( '?property', '?ref', '?p' )
230
-			->also( 'a', 'wikibase:Property' )
231
-			->also( 'rdfs:label', '?l' )
232
-			->filter( 'LANG(?l) = "en"' )
233
-			->limit( 10 );
227
+		$queryBuilder->select('?l')
228
+			->where('wd:Q5571382', '?p', 'wd:Q223243')
229
+			->where('?property', '?ref', '?p')
230
+			->also('a', 'wikibase:Property')
231
+			->also('rdfs:label', '?l')
232
+			->filter('LANG(?l) = "en"')
233
+			->limit(10);
234 234
 
235
-		$this->assertIsExpected( 'What_is_the_relation_between_Terrell_Buckley_and_Miami_Dolphins', $queryBuilder->format() );
235
+		$this->assertIsExpected('What_is_the_relation_between_Terrell_Buckley_and_Miami_Dolphins', $queryBuilder->format());
236 236
 	}
237 237
 
238 238
 	public function testAliasesOfPropertiesWhichAreUsedMoreThanOnce() {
239
-		$queryBuilder = new QueryBuilder( self::$prefixes + array(
239
+		$queryBuilder = new QueryBuilder(self::$prefixes + array(
240 240
 			'skos' => 'http://www.w3.org/2004/02/skos/core#'
241
-		) );
241
+		));
242 242
 
243
-		$queryBuilder->select( '?property', '?alias', '?occurences' )
243
+		$queryBuilder->select('?property', '?alias', '?occurences')
244 244
 			->subquery(
245 245
 				$queryBuilder->newSubquery()
246
-					->select( '?alias', '(COUNT (?alias) AS ?occurences)' )
247
-					->where( '?tmp', 'a', 'wikibase:Property' )
248
-					->also( 'skos:altLabel', '?alias' )
249
-					->filter( 'LANG (?alias) = "en"' )
250
-					->groupBy( '?alias' )
246
+					->select('?alias', '(COUNT (?alias) AS ?occurences)')
247
+					->where('?tmp', 'a', 'wikibase:Property')
248
+					->also('skos:altLabel', '?alias')
249
+					->filter('LANG (?alias) = "en"')
250
+					->groupBy('?alias')
251 251
 			)
252
-			->where( '?property', 'a', 'wikibase:Property' )
253
-			->also( 'skos:altLabel', '?alias' )
254
-			->filter( '?occurences > 1' )
255
-			->orderBy( '?alias' );
252
+			->where('?property', 'a', 'wikibase:Property')
253
+			->also('skos:altLabel', '?alias')
254
+			->filter('?occurences > 1')
255
+			->orderBy('?alias');
256 256
 
257
-		$this->assertIsExpected( 'Aliases_of_properties_which_are_used_more_than_once', $queryBuilder->format() );
257
+		$this->assertIsExpected('Aliases_of_properties_which_are_used_more_than_once', $queryBuilder->format());
258 258
 	}
259 259
 
260
-	private function assertIsExpected( $name, $sparql ) {
261
-		$expected = file_get_contents( __DIR__ . '/../data/wdqs_' . $name . '.rq' );
260
+	private function assertIsExpected($name, $sparql) {
261
+		$expected = file_get_contents(__DIR__ . '/../data/wdqs_' . $name . '.rq');
262 262
 
263
-		$this->assertEquals( $expected, $sparql, 'Query didn\'t match the expected content of integration_' . $name . '.rq' );
263
+		$this->assertEquals($expected, $sparql, 'Query didn\'t match the expected content of integration_' . $name . '.rq');
264 264
 	}
265 265
 
266 266
 }
Please login to merge, or discard this patch.
tests/integration/QueryFormatterTest.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -13,20 +13,20 @@
 block discarded – undo
13 13
 	/**
14 14
 	 * @dataProvider provideTestFormat
15 15
 	 */
16
-	public function testFormat( $name ) {
16
+	public function testFormat($name) {
17 17
 		$formatter = new QueryFormatter();
18
-		$sparql = file_get_contents( __DIR__ . '/../data/formatter_' . $name . '_in.rq' );
19
-		$expected = file_get_contents( __DIR__ . '/../data/formatter_' . $name . '_out.rq' );
18
+		$sparql = file_get_contents(__DIR__ . '/../data/formatter_' . $name . '_in.rq');
19
+		$expected = file_get_contents(__DIR__ . '/../data/formatter_' . $name . '_out.rq');
20 20
 
21
-		$this->assertEquals( $expected, $formatter->format( $sparql ),
22
-			'Input from formatter_' . $name . '_in.rq didn\'t produce the expected output.'  );
21
+		$this->assertEquals($expected, $formatter->format($sparql),
22
+			'Input from formatter_' . $name . '_in.rq didn\'t produce the expected output.');
23 23
 	}
24 24
 
25 25
 	public function provideTestFormat() {
26 26
 		return array(
27
-			'Query without line-breaks' => array( 'one_line' ),
28
-			'Query with lots of spaces' => array( 'many_spaces' ),
29
-			'Query with few spaces' => array( 'few_spaces' )
27
+			'Query without line-breaks' => array('one_line'),
28
+			'Query with lots of spaces' => array('many_spaces'),
29
+			'Query with few spaces' => array('few_spaces')
30 30
 		);
31 31
 	}
32 32
 
Please login to merge, or discard this patch.
tests/bootstrap.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -1,19 +1,19 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( PHP_SAPI !== 'cli' ) {
4
-	die( 'Not an entry point' );
3
+if (PHP_SAPI !== 'cli') {
4
+	die('Not an entry point');
5 5
 }
6 6
 
7
-error_reporting( E_ALL | E_STRICT );
8
-ini_set( 'display_errors', 1 );
7
+error_reporting(E_ALL | E_STRICT);
8
+ini_set('display_errors', 1);
9 9
 
10
-if ( !is_readable( __DIR__ . '/../vendor/autoload.php' ) ) {
11
-	die( 'You need to install this package with Composer before you can run the tests' );
10
+if (!is_readable(__DIR__ . '/../vendor/autoload.php')) {
11
+	die('You need to install this package with Composer before you can run the tests');
12 12
 }
13 13
 
14 14
 $autoLoader = require_once __DIR__ . '/../vendor/autoload.php';
15 15
 
16
-$autoLoader->addPsr4( 'Asparagus\\Tests\\', __DIR__ . '/unit/' );
17
-$autoLoader->addPsr4( 'Asparagus\\Tests\\Integration\\', __DIR__ . '/integration/' );
16
+$autoLoader->addPsr4('Asparagus\\Tests\\', __DIR__ . '/unit/');
17
+$autoLoader->addPsr4('Asparagus\\Tests\\Integration\\', __DIR__ . '/integration/');
18 18
 
19
-unset( $autoLoader );
19
+unset($autoLoader);
Please login to merge, or discard this patch.
tests/unit/QueryExecuterTest.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -13,67 +13,67 @@
 block discarded – undo
13 13
  */
14 14
 class QueryExecuterTest extends \PHPUnit_Framework_TestCase {
15 15
 
16
-	private function getHttpMock( $params ) {
17
-		$http = $this->getMockBuilder( 'Asparagus\Http' )
16
+	private function getHttpMock($params) {
17
+		$http = $this->getMockBuilder('Asparagus\Http')
18 18
 			->disableOriginalConstructor()
19 19
 			->getMock();
20 20
 
21
-		$http->expects( $this->once() )
22
-			->method( 'request' )
21
+		$http->expects($this->once())
22
+			->method('request')
23 23
 			->with(
24
-				$this->equalTo( 'test.example.com' ),
25
-				$this->equalTo( $params )
24
+				$this->equalTo('test.example.com'),
25
+				$this->equalTo($params)
26 26
 			)
27
-			->will( $this->returnValue( '{"results":"~=[,,_,,]:3"}' ) );
27
+			->will($this->returnValue('{"results":"~=[,,_,,]:3"}'));
28 28
 
29 29
 		return $http;
30 30
 	}
31 31
 
32 32
 	public function testExecute() {
33
-		$http = $this->getHttpMock( array(
33
+		$http = $this->getHttpMock(array(
34 34
 			'query' => 'FooBar',
35 35
 			'format' => 'json'
36
-		) );
36
+		));
37 37
 
38
-		$queryExecuter = new QueryExecuter( 'test.example.com', array(), $http );
39
-		$result = $queryExecuter->execute( 'FooBar' );
38
+		$queryExecuter = new QueryExecuter('test.example.com', array(), $http);
39
+		$result = $queryExecuter->execute('FooBar');
40 40
 
41
-		$this->assertEquals( '~=[,,_,,]:3', $result );
41
+		$this->assertEquals('~=[,,_,,]:3', $result);
42 42
 	}
43 43
 
44 44
 	public function testExecuteCustomParams() {
45
-		$http = $this->getHttpMock( array(
45
+		$http = $this->getHttpMock(array(
46 46
 			'fancy-query' => 'FooBar',
47 47
 			'format-nyan' => 'json'
48
-		) );
48
+		));
49 49
 
50
-		$queryExecuter = new QueryExecuter( 'test.example.com', array(
50
+		$queryExecuter = new QueryExecuter('test.example.com', array(
51 51
 			'queryParam' => 'fancy-query',
52 52
 			'formatParam' => 'format-nyan'
53
-		), $http );
53
+		), $http);
54 54
 
55
-		$result = $queryExecuter->execute( 'FooBar' );
55
+		$result = $queryExecuter->execute('FooBar');
56 56
 
57
-		$this->assertEquals( '~=[,,_,,]:3', $result );
57
+		$this->assertEquals('~=[,,_,,]:3', $result);
58 58
 	}
59 59
 
60 60
 	public function testExecuteQueryBuilder() {
61
-		$http = $this->getHttpMock( array(
61
+		$http = $this->getHttpMock(array(
62 62
 			'query' => 'SELECT * WHERE { }',
63 63
 			'format' => 'json'
64
-		) );
64
+		));
65 65
 
66
-		$queryExecuter = new QueryExecuter( 'test.example.com', array(), $http );
67
-		$result = $queryExecuter->execute( new QueryBuilder() );
66
+		$queryExecuter = new QueryExecuter('test.example.com', array(), $http);
67
+		$result = $queryExecuter->execute(new QueryBuilder());
68 68
 
69
-		$this->assertEquals( '~=[,,_,,]:3', $result );
69
+		$this->assertEquals('~=[,,_,,]:3', $result);
70 70
 	}
71 71
 
72 72
 	public function testExecuteInvalidArgument() {
73
-		$queryExecuter = new QueryExecuter( 'test.example.com' );
74
-		$this->setExpectedException( 'InvalidArgumentException' );
73
+		$queryExecuter = new QueryExecuter('test.example.com');
74
+		$this->setExpectedException('InvalidArgumentException');
75 75
 
76
-		$queryExecuter->execute( null );
76
+		$queryExecuter->execute(null);
77 77
 	}
78 78
 
79 79
 }
Please login to merge, or discard this patch.