Lines 96.55% 28 / 29
Methods 88.88% 8 / 9
Classes 0.00% 0 / 1
Covered by tests of size
Name Lines Methods CRAP
 __construct 95.23% 20 / 21 0.00% 0 / 1 4
 getServer 100.00% 1 / 1 100.00% 1 / 1 1
 getPort 100.00% 1 / 1 100.00% 1 / 1 1
 getUser 100.00% 1 / 1 100.00% 1 / 1 1
 getPassword 100.00% 1 / 1 100.00% 1 / 1 1
 getDatabase 100.00% 1 / 1 100.00% 1 / 1 1
 getPrefix 100.00% 1 / 1 100.00% 1 / 1 1
 getType 100.00% 1 / 1 100.00% 1 / 1 1
 getSchema 100.00% 1 / 1 100.00% 1 / 1 1
24readonly class DatabaseConfiguration
25{
26    private string $server;
27
28    private ?int $port;
29
30    private string $user;
31
32    private string $password;
33
34    private string $database;
35
36    private string $prefix;
37
38    private string $type;
39
40    private ?string $schema;
41
42    public function __construct(string $filename)
43    {
44        if (!is_readable($filename)) {
45            throw new RuntimeException(sprintf('Database configuration file "%s" is not readable.', $filename));
46        }
47
48        $DB = [
49            'server' => '',
50            'port' => '',
51            'user' => '',
52            'password' => '',
53            'db' => '',
54            'prefix' => '',
55            'type' => '',
56            'schema' => '',
57        ];
58
59        include $filename;
60
61        $this->server = $DB['server'];
62        $this->port = $DB['port'] === '' ? null : (int) $DB['port'];
63        $this->user = $DB['user'];
64        $this->password = $DB['password'];
65        $this->database = $DB['db'];
66        $this->prefix = $DB['prefix'];
67        $this->type = $DB['type'];
68        $this->schema = $DB['schema'] === '' ? null : $DB['schema'];
69    }
70
71    public function getServer(): string
72    {
73        return $this->server;
74    }
75
76    public function getPort(): ?int
77    {
78        return $this->port;
79    }
80
81    public function getUser(): string
82    {
83        return $this->user;
84    }
85
86    public function getPassword(): string
87    {
88        return $this->password;
89    }
90
91    public function getDatabase(): string
92    {
93        return $this->database;
94    }
95
96    public function getPrefix(): string
97    {
98        return $this->prefix;
99    }
100
101    public function getType(): string
102    {
103        return $this->type;
104    }
105
106    public function getSchema(): ?string
107    {
108        return $this->schema;
109    }
110}