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

Passed
Pull Request — master (#915)
by
unknown
04:08
created

MySqlProperties::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 13
rs 9.9
1
<?php declare(strict_types=1);
2
3
use Dotenv\Dotenv;
4
5
class MySqlProperties {
6
	private const CONFIG_MYSQL_HOST = "MYSQL_HOST";
7
	private const CONFIG_MYSQL_USER = "MYSQL_USER";
8
	private const CONFIG_MYSQL_PASSWORD = "MYSQL_PASSWORD";
9
	private const CONFIG_MYSQL_PORT = "MYSQL_PORT";
10
	private const CONFIG_MYSQL_DATABASE = "MYSQL_DATABASE";
11
	private string $host;
12
	private string $user;
13
	private string $password;
14
	private int $port;
15
	private string $databaseName;
16
17
	public function __construct() {
18
		$environmentFile = self::determineConfigEnvironmentFile();
19
		$config = Dotenv::createArrayBacked(ROOT, $environmentFile);
20
		$array = $config->load();
21
		self::validateConfig($config);
22
		[
23
			MySqlProperties::CONFIG_MYSQL_HOST => $this->host,
24
			MySqlProperties::CONFIG_MYSQL_USER => $this->user,
25
			MySqlProperties::CONFIG_MYSQL_PASSWORD => $this->password,
26
			MySqlProperties::CONFIG_MYSQL_PORT => $port,
27
			MySqlProperties::CONFIG_MYSQL_DATABASE => $this->databaseName,
28
		] = $array;
29
		$this->port = (int)$port;
30
	}
31
32
	public static function determineConfigEnvironmentFile(): string {
33
		$environment = "";
34
		if (isset($_ENV["MYSQL_CONFIG_ENVIRONMENT"])) {
35
			$environment = $_ENV["MYSQL_CONFIG_ENVIRONMENT"];
36
		}
37
		return $environment . ".env";
38
	}
39
40
	public static function validateConfig(Dotenv $config) {
41
		$config->required(self::CONFIG_MYSQL_HOST);
42
		$config->required(self::CONFIG_MYSQL_USER);
43
		$config->required(self::CONFIG_MYSQL_PASSWORD);
44
		$config->required(self::CONFIG_MYSQL_PORT)->isInteger();
45
		$config->required(self::CONFIG_MYSQL_DATABASE);
46
	}
47
48
	public function getHost(): string {
49
		return $this->host;
50
	}
51
52
	public function getUser(): string {
53
		return $this->user;
54
	}
55
56
	public function getPassword(): string {
57
		return $this->password;
58
	}
59
60
	public function getPort(): int {
61
		return $this->port;
62
	}
63
64
	public function getDatabaseName(): string {
65
		return $this->databaseName;
66
	}
67
}
68