DbPackage   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 2
eloc 15
c 2
b 0
f 1
dl 0
loc 25
rs 10
ccs 13
cts 13
cp 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A addToContainer() 0 20 2
1
<?php declare(strict_types=1);
2
3
namespace Bone\Db;
4
5
use Barnacle\Container;
6
use Barnacle\RegistrationInterface;
7
use Barnacle\Exception\NotFoundException;
8
use PDO;
9
10
class DbPackage implements RegistrationInterface
11
{
12
    /**
13
     * @param Container $c
14
     */
15 2
    public function addToContainer(Container $c)
16
    {
17 2
        if ($c->has('db')) {
18
            $c[PDO::class] = $c->factory(function (Container $c): PDO {
19 1
                $credentials = $c->get('db');
20 1
                $host = $credentials['host'];
21 1
                $db = $credentials['dbname'];
22 1
                $user = $credentials['user'];
23 1
                $pass = $credentials['password'];
24
25 1
                $dbConnection = new PDO('mysql:host=' . $host . ';dbname=' . $db, $user, $pass, [
26 1
                    PDO::ATTR_EMULATE_PREPARES => false,
27
                    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
28
                ]);
29
30 1
                return $dbConnection;
31 1
            });
32
        } else {
33 1
            throw new NotFoundException('DbPackage is registered but there is no db config. See the 
34 1
            delboy1978uk/bone-db README.', 418);
35
        }
36 1
    }
37
}
38