Skip to content

Commit

Permalink
Always return array
Browse files Browse the repository at this point in the history
  • Loading branch information
malberts committed Nov 13, 2023
1 parent 9f9c5c7 commit d8858da
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 9 deletions.
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,3 @@ parameters:
message: "#^Method ProfessionalWiki\\\\SPARQL\\\\SparqlLuaQueryRunner\\:\\:runQuery\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/SparqlLuaQueryRunner.php

-
message: "#^Method ProfessionalWiki\\\\SPARQL\\\\SparqlLuaQueryRunner\\:\\:runQuery\\(\\) should return array\\|null but returns mixed\\.$#"
count: 1
path: src/SparqlLuaQueryRunner.php
2 changes: 1 addition & 1 deletion src/SparqlLua.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function register(): array {
);
}

private function runSparqlQuery( string $sparql ): array|null {
private function runSparqlQuery( string $sparql ): array {
$sparqlEndpoint = MediaWikiServices::getInstance()->getMainConfig()->get( 'SPARQLEndpoint' );

if ( !is_string( $sparqlEndpoint ) ) {
Expand Down
4 changes: 2 additions & 2 deletions src/SparqlLuaQueryRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function __construct(
) {
}

public function runQuery( string $sparql ): array|null {
public function runQuery( string $sparql ): array {
$options = [
'postData' => [
'query' => $sparql,
Expand All @@ -23,7 +23,7 @@ public function runQuery( string $sparql ): array|null {
];
$response = $this->requestFactory->request( 'POST', $this->sparqlEndpoint, $options );

return $response !== null ? json_decode( $response, true ) : null;
return $response !== null ? (array)json_decode( $response, true ) : [];
}

}
2 changes: 1 addition & 1 deletion tests/integration/SparqlLuaQueryRunnerIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private function newQueryRunner(): SparqlLuaQueryRunner {
public function testRunQueryWhenSparqlQueryIsEmpty(): void {
$sparqlQuery = '';
$result = $this->newQueryRunner()->runQuery( $sparqlQuery );
$this->assertNull( $result );
$this->assertSame( [], $result );
}

public function testRunQueryReturnsRightHeadVars(): void {
Expand Down

0 comments on commit d8858da

Please sign in to comment.