Passed
Push — master ( 2a5f36...212476 )
by Patrick
01:25
created

LaravelNomadServiceProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 68.42%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 7
dl 0
loc 43
ccs 13
cts 19
cp 0.6842
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 4 1
B register() 0 24 2
1
<?php
2
namespace ShiftOneLabs\LaravelNomad;
3
4
use Illuminate\Database\Connection;
5
use Illuminate\Support\ServiceProvider;
6
use ShiftOneLabs\LaravelNomad\Extension\Database\MySqlConnection;
7
use ShiftOneLabs\LaravelNomad\Extension\Database\SQLiteConnection;
8
use ShiftOneLabs\LaravelNomad\Extension\Database\PostgresConnection;
9
use ShiftOneLabs\LaravelNomad\Extension\Database\SqlServerConnection;
10
11
class LaravelNomadServiceProvider extends ServiceProvider
12
{
13
14
    /**
15
     * Bootstrap any application services.
16
     *
17
     * @return void
18
     */
19
    public function boot()
20
    {
21
        //
22
    }
23
24
    /**
25
     * Register any application services.
26
     *
27
     * @return void
28
     */
29 37
    public function register()
30
    {
31 37
        if (method_exists(Connection::class, 'resolverFor')) {
32
            // Laravel 5.4 and newer
33
            Connection::resolverFor('mysql', function ($connection, $database, $prefix, $config) {
34 7
                return new MySqlConnection($connection, $database, $prefix, $config);
35 37
            });
36
            Connection::resolverFor('pgsql', function ($connection, $database, $prefix, $config) {
37 7
                return new PostgresConnection($connection, $database, $prefix, $config);
38 37
            });
39
            Connection::resolverFor('sqlite', function ($connection, $database, $prefix, $config) {
40 7
                return new SQLiteConnection($connection, $database, $prefix, $config);
41 37
            });
42 37
            Connection::resolverFor('sqlsrv', function ($connection, $database, $prefix, $config) {
43 7
                return new SqlServerConnection($connection, $database, $prefix, $config);
44 37
            });
45 37
        } else {
46
            // Laravel 5.3 and older
47
            $this->app->bind('db.connection.mysql', 'ShiftOneLabs\LaravelNomad\Extension\Database\MySqlConnection');
48
            $this->app->bind('db.connection.pgsql', 'ShiftOneLabs\LaravelNomad\Extension\Database\PostgresConnection');
49
            $this->app->bind('db.connection.sqlite', 'ShiftOneLabs\LaravelNomad\Extension\Database\SQLiteConnection');
50
            $this->app->bind('db.connection.sqlsrv', 'ShiftOneLabs\LaravelNomad\Extension\Database\SqlServerConnection');
51
        }
52 37
    }
53
}
54