| Conditions | 2 |
| Paths | 2 |
| Total Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 6 |
| Changes | 0 | ||
| 1 | <?php declare(strict_types=1); |
||
| 15 | public function addToContainer(Container $c) |
||
| 16 | { |
||
| 17 | if ($c->has('db')) { |
||
| 18 | $c[PDO::class] = $c->factory(function (Container $c): PDO { |
||
| 19 | $credentials = $c->get('db'); |
||
| 20 | $host = $credentials['host']; |
||
| 21 | $db = $credentials['database']; |
||
| 22 | $user = $credentials['user']; |
||
| 23 | $pass = $credentials['pass']; |
||
| 24 | |||
| 25 | $dbConnection = new PDO('mysql:host=' . $host . ';dbname=' . $db, $user, $pass, [ |
||
| 26 | PDO::ATTR_EMULATE_PREPARES => false, |
||
| 27 | PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, |
||
| 28 | ]); |
||
| 29 | |||
| 30 | return $dbConnection; |
||
| 31 | }); |
||
| 32 | } else { |
||
| 33 | throw new NotFoundException('DbPackage is registered but there is no db config. See the |
||
| 34 | delboy1978uk/bone-db README.', 418); |
||
| 35 | } |
||
| 36 | } |
||
| 37 | } |
||
| 38 |