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
Pull Request — master (#1094)
by Dan
04:47
created

DatabaseRecord   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
dl 0
loc 59
rs 10
c 1
b 0
f 0
wmc 13

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A hasField() 0 2 1
A getField() 0 2 1
A getBoolean() 0 4 1
A getInt() 0 2 1
A getString() 0 2 1
A getMicrotime() 0 4 1
A getFloat() 0 2 1
A getObject() 0 9 4
A getRow() 0 2 1
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