for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Install GitHub App
<?php declare(strict_types=1);
namespace Smr;
use Exception;
use Generator;
use mysqli_result;
use RuntimeException;
/**
* Holds the result of a Database query (e.g. read or write).
*/
class DatabaseResult {
public function __construct(
private readonly mysqli_result $dbResult
) {}
* Use to iterate over the records from the result set.
* @return \Generator<DatabaseRecord>
public function records(): Generator {
foreach ($this->dbResult as $dbRecord) {
yield new DatabaseRecord($dbRecord);
}
* Use when exactly one record is expected from the result set.
public function record(): DatabaseRecord {
if ($this->getNumRecords() != 1) {
throw new RuntimeException('One record required, but found ' . $this->getNumRecords());
return new DatabaseRecord($this->dbResult->fetch_assoc());
public function getNumRecords(): int {
$numRows = $this->dbResult->num_rows;
if (is_string($numRows)) {
is_string($numRows)
false
throw new Exception('Number of rows is too large to represent as an int: ' . $numRows);
return $numRows;
public function hasRecord(): bool {
return $this->getNumRecords() > 0;