Skip to content

Commit

Permalink
Merge pull request #19 from shotanue/feature/empty-query-row-result-r…
Browse files Browse the repository at this point in the history
…euturns-null

[BC Break] getRow returns null if the query result is empty
  • Loading branch information
koriym authored Oct 8, 2021
2 parents 1e40c56 + 59a617d commit 6317704
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/DbQueryInterceptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(SqlQueryInterface $sqlQuery, MediaQueryLoggerInterfa
}

/**
* @return array<mixed>|object|PagesInterface
* @return array<mixed>|object|PagesInterface|null
*/
public function invoke(MethodInvocation $invocation)
{
Expand Down Expand Up @@ -72,7 +72,7 @@ private function getFetchMode(DbQuery $dbQuery): int
* @param PDO::FETCH_ASSOC|PDO::FETCH_CLASS|PDO::FETCH_FUNC $fetchStyle
* @param int|string|callable $fetchArg
*
* @return array<mixed>|object
* @return array<mixed>|object|null
*/
private function sqlQuery(string $queryId, array $values, int $fetchStyle, $fetchArg)
{
Expand Down
2 changes: 1 addition & 1 deletion src/SqlQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function getRow(string $sqlId, array $values = [], int $fetchMode = PDO::
{
$rowList = $this->perform($sqlId, $values, $fetchMode, $fetchArg);
if (! count($rowList)) {
return [];
return null;
}

$item = $rowList[0];
Expand Down
2 changes: 1 addition & 1 deletion src/SqlQueryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function exec(string $sqlId, array $values = [], int $fetchMode = PDO::FE
* @param PDO::FETCH_ASSOC|PDO::FETCH_CLASS|PDO::FETCH_FUNC $fetchMode
* @param int|string|callable $fetchArg
*
* @return array<mixed>|object
* @return array<mixed>|object|null
*/
public function getRow(string $sqlId, array $values = [], int $fetchMode = PDO::FETCH_ASSOC, $fetchArg = '');

Expand Down
2 changes: 1 addition & 1 deletion tests/SqlQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function testGetRowNotFound(): void
{
$result = $this->sqlQuery->getRow('todo_item', ['id' => '__invalid__']);

$this->assertSame([], $result);
$this->assertNull($result);
}

/**
Expand Down

0 comments on commit 6317704

Please sign in to comment.