DatabaseServiceProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 10 2
A register() 0 7 2
1
<?php
2
3
namespace CloudyCity\LaravelBuilderMacros\Providers;
4
5
use CloudyCity\LaravelBuilderMacros\Library\Database\MySqlConnection;
6
use Illuminate\Database\Connection;
7
use Illuminate\Support\ServiceProvider;
8
9
class DatabaseServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Override the default connection for MySQL. This allows us to use `replace` etc.
13
     *
14
     * @link https://stidges.com/extending-the-connection-class-in-laravel
15
     * @link https://gist.github.com/VinceG/0fb570925748ab35bc53f2a798cb517c
16
     *
17
     * @return void
18
     */
19
    public function boot()
20
    {
21
        // 5.4 and above will use this method to bind
22
        if (method_exists(Connection::class, 'resolverFor')) {
23
            /* @noinspection PhpUndefinedMethodInspection */
24
            Connection::resolverFor('mysql', function ($connection, $database, $prefix, $config) {
25
                return new MySqlConnection($connection, $database, $prefix, $config);
26
            });
27
        }
28
    }
29
30
    /**
31
     * Register the service provider.
32
     *
33
     * @return void
34
     */
35
    public function register()
36
    {
37
        // 5.3 and below will use this method to bind
38
        if (! method_exists(Connection::class, 'resolverFor')) {
39
            $this->app->bind('db.connection.mysql', MySqlConnection::class);
40
        }
41
    }
42
}
43