Skip to content

Commit

Permalink
add locateRowCount() helper method to use array_key_exists
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Sep 10, 2020
1 parent ab146a8 commit 30486b3
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/Adapter/DbSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Laminas\Db\Sql\Expression;
use Laminas\Db\Sql\Select;
use Laminas\Db\Sql\Sql;
use LogicException;

class DbSelect implements AdapterInterface
{
Expand Down Expand Up @@ -122,9 +123,7 @@ public function count()
$result = $statement->execute();
$row = $result->current();

$this->rowCount = isset($row[self::ROW_COUNT_COLUMN_NAME])
? (int) $row[self::ROW_COUNT_COLUMN_NAME]
: (int) $row[strtolower(self::ROW_COUNT_COLUMN_NAME)];
$this->rowCount = $this->locateRowCount($row);

return $this->rowCount;
}
Expand Down Expand Up @@ -167,4 +166,18 @@ public function getArrayCopy()
),
];
}

private function locateRowCount(array $row)
{
if (array_key_exists(self::ROW_COUNT_COLUMN_NAME, $row)) {
return (int) $row[self::ROW_COUNT_COLUMN_NAME];
}

$lowerCaseColumnName = strtolower(self::ROW_COUNT_COLUMN_NAME);
if (array_key_exists($lowerCaseColumnName, $row)) {
return (int) $row[$lowerCaseColumnName];
}

throw new LogicException('Unable to determine row count; missing row count column in result');
}
}

0 comments on commit 30486b3

Please sign in to comment.