Passed
Push — next ( cade46...f034dd )
by Bas
05:34 queued 02:21
created

AranguentServiceProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 31
dl 0
loc 74
ccs 39
cts 39
cp 1
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 12 3
A register() 0 38 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LaravelFreelancerNL\Aranguent;
6
7
use Illuminate\Support\ServiceProvider;
8
use LaravelFreelancerNL\Aranguent\Eloquent\Model;
9
use LaravelFreelancerNL\Aranguent\Schema\Grammar as SchemaGrammar;
10
11
class AranguentServiceProvider extends ServiceProvider
12
{
13
    /**
14
     * Components to register on the provider.
15
     *
16
     * @var array<string>
17
     */
18
    protected $components = [
19
        'Migration',
20
    ];
21
22
    /**
23
     * Bootstrap services.
24
     *
25
     * @return void
26
     */
27 343
    public function boot()
28
    {
29 343
        if (isset($this->app['db'])) {
30 343
            Model::setConnectionResolver($this->app['db']);
31
        }
32
33 343
        if (isset($this->app['events'])) {
34 343
            Model::setEventDispatcher($this->app['events']);
35
        }
36
37 343
        $this->publishes([
38 343
            __DIR__ . '/../config/arangodb.php' => config_path('arangodb.php'),
39 343
        ]);
40
    }
41
42
    /**
43
     * Register services.
44
     *
45
     * @return void
46
     */
47 343
    public function register()
48
    {
49 343
        $this->mergeConfigFrom(
50 343
            __DIR__ . '/../config/arangodb.php',
51 343
            'arangodb'
52 343
        );
53
54 343
        $this->app->singleton(\Illuminate\Database\Migrations\Migrator::class, function ($app) {
55 343
            return $app['migrator'];
56 343
        });
57
58 343
        $this->app->resolving(
59 343
            'db',
60 343
            function ($db) {
61 343
                $db->extend(
62 343
                    'arangodb',
63 343
                    function ($config, $name) {
64 343
                        $config['name'] = $name;
65 343
                        $connection = new Connection($config);
66 343
                        $connection->setSchemaGrammar(new SchemaGrammar());
67
68 343
                        return $connection;
69 343
                    }
70 343
                );
71 343
            }
72 343
        );
73
74 343
        $this->app->resolving(
75 343
            function () {
76 343
                if (class_exists('Illuminate\Foundation\AliasLoader')) {
77 343
                    $loader = \Illuminate\Foundation\AliasLoader::getInstance();
78 343
                    $loader->alias('Eloquent', 'LaravelFreelancerNL\Aranguent\Eloquent\Model');
79
                }
80 343
            }
81 343
        );
82
83 343
        $this->app->register('LaravelFreelancerNL\Aranguent\Providers\MigrationServiceProvider');
84 343
        $this->app->register('LaravelFreelancerNL\Aranguent\Providers\CommandServiceProvider');
85
    }
86
}
87