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

Failed Conditions
Push — master ( f174b5...646f17 )
by Dan
21s queued 18s
created

DatabaseRecord::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Smr;
4
5
class DatabaseRecord {
6
7
	/**
8
	 * @param array $dbRecord A record from a DatabaseResult.
9
	 */
10
	public function __construct(
11
		private array $dbRecord
12
	) {}
13
14
	public function hasField(string $name) : bool {
15
		return isset($this->dbRecord[$name]);
16
	}
17
18
	public function getField(string $name) : ?string {
19
		return $this->dbRecord[$name];
20
	}
21
22
	/**
23
	 * Get a string-only field from the database record.
24
	 * If the field can be null, use `getField` instead.
25
	 */
26
	public function getString(string $name) : string {
27
		return $this->dbRecord[$name];
28
	}
29
30
	public function getBoolean(string $name) : bool {
31
		return match($this->dbRecord[$name]) {
32
			'TRUE' => true,
33
			'FALSE' => false,
34
		};
35
	}
36
37
	public function getInt(string $name) : int {
38
		return (int)$this->dbRecord[$name];
39
	}
40
41
	public function getFloat(string $name) : float {
42
		return (float)$this->dbRecord[$name];
43
	}
44
45
	public function getMicrotime(string $name) : string {
46
		// All digits of precision are stored in a MySQL bigint
47
		$data = $this->dbRecord[$name];
48
		return sprintf('%f', $data / 1E6);
49
	}
50
51
	public function getObject(string $name, bool $compressed = false, bool $nullable = false) : mixed {
52
		$object = $this->getField($name);
53
		if ($nullable === true && $object === null) {
54
			return null;
55
		}
56
		if ($compressed === true) {
57
			$object = gzuncompress($object);
0 ignored issues
show
Bug introduced by
It seems like $object can also be of type null; however, parameter $data of gzuncompress() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

57
			$object = gzuncompress(/** @scrutinizer ignore-type */ $object);
Loading history...
58
		}
59
		return unserialize($object);
0 ignored issues
show
Bug introduced by
It seems like $object can also be of type null; however, parameter $data of unserialize() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

59
		return unserialize(/** @scrutinizer ignore-type */ $object);
Loading history...
60
	}
61
62
	public function getRow() : array {
63
		return $this->dbRecord;
64
	}
65
66
}
67