ApiDriverServiceProvider   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 12 2
A boot() 0 6 1
1
<?php
2
3
namespace TomHart\Database;
4
5
use Illuminate\Database\Connection;
6
use Illuminate\Support\ServiceProvider;
7
use TomHart\Database\Database\ApiConnection;
8
9
class ApiDriverServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Register any application services.
13
     *
14
     * @return void
15
     */
16
    public function register(): void
17
    {
18
        Connection::resolverFor('api', static function ($connection, $database, $prefix, $config) {
19
            if (app()->has(ApiConnection::class)) {
20
                return app(ApiConnection::class);
21
            }
22
23
            return new ApiConnection($connection, $database, $prefix, $config);
24
        });
25
26
        $this->mergeConfigFrom(__DIR__ . '/../config/api-database.php', 'api-database');
27
    }
28
29
    /**
30
     * Boot the service.
31
     */
32
    public function boot(): void
33
    {
34
        $this->publishes([
35
            __DIR__ . '/../config/api-database.php' => config_path('api-database.php'),
36
        ], 'config');
37
    }
38
}
39