| Conditions | 4 |
| Paths | 4 |
| Total Lines | 19 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 9 |
| CRAP Score | 4.0961 |
| Changes | 3 | ||
| Bugs | 1 | Features | 2 |
| 1 | <?php |
||
| 16 | 3 | public function getDsn($config) |
|
| 17 | { |
||
| 18 | 3 | $host = arr_get($config, "host"); |
|
| 19 | 3 | $port = arr_get($config, "port"); |
|
| 20 | 3 | $dbname = arr_get($config, "dbname"); |
|
| 21 | 3 | $charset = arr_get($config, "charset", "utf8"); |
|
| 22 | |||
| 23 | 3 | if (empty($host)) { |
|
| 24 | throw new \Exception("\"host\" can not be blank."); |
||
| 25 | } |
||
| 26 | |||
| 27 | 3 | if (empty($dbname)) { |
|
| 28 | throw new \Exception("\"dbname\" can not be blank."); |
||
| 29 | } |
||
| 30 | |||
| 31 | return $port ? |
||
| 32 | 3 | sprintf('mysql:host=%s;port=%s;dbname=%s;charset=%s', $host, $port, $dbname, $charset): |
|
| 33 | 3 | sprintf('mysql:host=%s;dbname=%s;charset=%s', $host, $dbname, $charset); |
|
| 34 | } |
||
| 35 | |||
| 45 |