Passed
Push — shift-56240 ( 9aecfa...6d7800 )
by Bas
02:43
created

AranguentServiceProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Test Coverage

Coverage 97.06%

Importance

Changes 0
Metric Value
wmc 3
eloc 29
c 0
b 0
f 0
dl 0
loc 71
ccs 33
cts 34
cp 0.9706
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 5 1
A register() 0 43 2
1
<?php
2
3
namespace LaravelFreelancerNL\Aranguent;
4
5
use Illuminate\Support\ServiceProvider;
6
use LaravelFreelancerNL\Aranguent\Eloquent\Model;
7
use Illuminate\Database\Migrations\MigrationCreator as IlluminateMigrationCreator;
8
use LaravelFreelancerNL\Aranguent\Migrations\MigrationCreator;
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
17
     */
18
    protected $components = [
19
        'Migration',
20
    ];
21
22
    /**
23
     * Bootstrap services.
24
     *
25
     * @return void
26
     */
27 205
    public function boot()
28
    {
29 205
        Model::setConnectionResolver($this->app['db']);
30
31 205
        Model::setEventDispatcher($this->app['events']);
32 205
    }
33
34
    /**
35
     * Register services.
36
     *
37
     * @return void
38
     */
39 205
    public function register()
40
    {
41
        /**
42
         * When the MigrationCreator complains about an unset $customStubPath
43
         * we resolve it here
44
         */
45 205
        $this->app->when(MigrationCreator::class)
46 205
            ->needs('$customStubPath')
47 205
            ->give(function () {
48 205
                return __DIR__ . '/../stubs';
49 205
            });
50 205
        $this->app->when(IlluminateMigrationCreator::class)
51 205
            ->needs('$customStubPath')
52 205
            ->give(function () {
53
                return __DIR__ . '/../stubs';
54 205
            });
55
56 205
        $this->app->resolving(
57 205
            'db',
58 205
            function ($db) {
59 205
                $db->extend(
60 205
                    'arangodb',
61 205
                    function ($config, $name) {
62 205
                        $config['name'] = $name;
63 205
                        $connection = new Connection($config);
64 205
                        $connection->setSchemaGrammar(new SchemaGrammar());
65
66 205
                        return $connection;
67 205
                    }
68
                );
69 205
            }
70
        );
71
72 205
        $this->app->resolving(
73 205
            function () {
74 205
                if (class_exists('Illuminate\Foundation\AliasLoader')) {
75 205
                    $loader = \Illuminate\Foundation\AliasLoader::getInstance();
76 205
                    $loader->alias('Eloquent', 'LaravelFreelancerNL\Aranguent\Eloquent\Model');
77
                }
78 205
            }
79
        );
80
81 205
        $this->app->register('LaravelFreelancerNL\Aranguent\Providers\CommandServiceProvider');
82 205
    }
83
}
84