Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

DatabaseResult   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 36
rs 10
c 1
b 0
f 0
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getNumRecords() 0 6 2
A __construct() 0 3 1
A records() 0 3 2
A hasRecord() 0 2 1
A record() 0 5 2
1
<?php declare(strict_types=1);
2
3
namespace Smr;
4
5
use Exception;
6
use Generator;
7
use mysqli_result;
8
use RuntimeException;
9
10
/**
11
 * Holds the result of a Database query (e.g. read or write).
12
 */
13
class DatabaseResult {
14
15
	public function __construct(
16
		private readonly mysqli_result $dbResult
17
	) {}
18
19
	/**
20
	 * Use to iterate over the records from the result set.
21
	 * @return \Generator<DatabaseRecord>
22
	 */
23
	public function records(): Generator {
24
		foreach ($this->dbResult as $dbRecord) {
25
			yield new DatabaseRecord($dbRecord);
26
		}
27
	}
28
29
	/**
30
	 * Use when exactly one record is expected from the result set.
31
	 */
32
	public function record(): DatabaseRecord {
33
		if ($this->getNumRecords() != 1) {
34
			throw new RuntimeException('One record required, but found ' . $this->getNumRecords());
35
		}
36
		return new DatabaseRecord($this->dbResult->fetch_assoc());
37
	}
38
39
	public function getNumRecords(): int {
40
		$numRows = $this->dbResult->num_rows;
41
		if (is_string($numRows)) {
0 ignored issues
show
introduced by
The condition is_string($numRows) is always false.
Loading history...
42
			throw new Exception('Number of rows is too large to represent as an int: ' . $numRows);
43
		}
44
		return $numRows;
45
	}
46
47
	public function hasRecord(): bool {
48
		return $this->getNumRecords() > 0;
49
	}
50
51
}
52