DatabaseServiceProvider   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
eloc 10
c 2
b 0
f 0
dl 0
loc 33
ccs 0
cts 11
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 6 1
A registerConnectionServices() 0 16 1
1
<?php
2
3
namespace Ianrizky\Illuminate\Database;
4
5
use Ianrizky\Illuminate\Database\Connectors\ConnectionFactory as CustomConnectionFactory;
6
use Illuminate\Database\DatabaseManager;
7
use Illuminate\Database\DatabaseServiceProvider as BaseDatabaseServiceProvider;
8
9
class DatabaseServiceProvider extends BaseDatabaseServiceProvider
10
{
11
    /**
12
     * {@inheritDoc}
13
     */
14
    public function register()
15
    {
16
        parent::register();
17
18
        $this->mergeConfigFrom(
19
            __DIR__ . '/../../../config/database.php', 'database'
20
        );
21
    }
22
23
    /**
24
     * {@inheritDoc}
25
     */
26
    protected function registerConnectionServices()
27
    {
28
        /**
29
         * The db.factory container instance has been changed
30
         * to implement custom query builder.
31
         */
32
        $this->app->singleton('db.factory', function ($app) {
33
            return new CustomConnectionFactory($app);
34
        });
35
36
        $this->app->singleton('db', function ($app) {
37
            return new DatabaseManager($app, $app['db.factory']);
38
        });
39
40
        $this->app->bind('db.connection', function ($app) {
41
            return $app['db']->connection();
42
        });
43
    }
44
}
45