Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
53.85% |
7 / 13 |
|
33.33% |
1 / 3 |
CRAP | |
0.00% |
0 / 1 |
DB | |
53.85% |
7 / 13 |
|
33.33% |
1 / 3 |
5.57 | |
0.00% |
0 / 1 |
connect | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
connectToTestDB | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
getConnection | |
66.67% |
2 / 3 |
|
0.00% |
0 / 1 |
2.15 |
1 | <?php |
2 | /** @noinspection PhpUnhandledExceptionInspection */ |
3 | declare(strict_types=1); |
4 | |
5 | class DB { |
6 | private static PDO $pdo; |
7 | |
8 | static function connect(): void { |
9 | self::$pdo = new PDO( |
10 | "mysql:host=" . SystemConfig::$database_host . ";port=" . SystemConfig::$database_port . ";dbname=" . SystemConfig::$database_name, |
11 | SystemConfig::$database_user, |
12 | SystemConfig::$database_password |
13 | ); |
14 | } |
15 | |
16 | static function connectToTestDB(): void { |
17 | self::$pdo = new PDO( |
18 | "mysql:host=" . SystemConfig::$database_host . ";port=" . SystemConfig::$database_port . ";dbname=TEST_" . SystemConfig::$database_name, |
19 | SystemConfig::$database_user, |
20 | SystemConfig::$database_password |
21 | ); |
22 | } |
23 | |
24 | static function getConnection(): PDO { |
25 | if (!isset(self::$pdo)) { |
26 | throw new Exception("DB connection not set up yet."); |
27 | } |
28 | return self::$pdo; |
29 | } |
30 | } |