| Conditions | 4 |
| Paths | 3 |
| Total Lines | 15 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 11 |
| CRAP Score | 4 |
| Changes | 0 | ||
| 1 | <?php |
||
| 23 | 7 | public function createPdo(Config $config): PDO |
|
| 24 | { |
||
| 25 | 7 | if ('' === $config->dbDsn()) { |
|
| 26 | 1 | throw new \RuntimeException('No database DSN is configured'); |
|
| 27 | } |
||
| 28 | |||
| 29 | try { |
||
| 30 | 6 | return new PDO($config->dbDsn(), $config->dbUsername(), $config->dbPassword()); |
|
| 31 | 1 | } catch (\Throwable $exception) { |
|
| 32 | 1 | throw new \RuntimeException(sprintf( |
|
| 33 | 1 | "Unable to create PDO using\nDSN: %s,\nUsername: '%s',\nPassword: %s.", |
|
| 34 | 1 | $config->dbDsn(), |
|
| 35 | 1 | $config->dbUsername(), |
|
| 36 | 1 | ('' === $config->dbPassword()) ? 'empty' : 'not empty' |
|
| 37 | 1 | ), 0, $exception); |
|
| 38 | } |
||
| 41 |