Passed
Push — devops/improve-workflows ( 6cf8af...f0d735 )
by Bas
02:53
created

AranguentServiceProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Test Coverage

Coverage 96.15%

Importance

Changes 0
Metric Value
wmc 3
eloc 29
c 0
b 0
f 0
dl 0
loc 71
ccs 25
cts 26
cp 0.9615
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 217
    public function boot()
28
    {
29 217
        Model::setConnectionResolver($this->app['db']);
30
31 217
        Model::setEventDispatcher($this->app['events']);
32
    }
33
34
    /**
35
     * Register services.
36
     *
37
     * @return void
38
     */
39 217
    public function register()
40
    {
41
        /**
42
         * When the MigrationCreator complains about an unset $customStubPath
43
         * we resolve it here
44
         */
45 217
        $this->app->when(MigrationCreator::class)
46 217
            ->needs('$customStubPath')
47 217
            ->give(function () {
48 217
                return __DIR__ . '/../stubs';
49
            });
50 217
        $this->app->when(IlluminateMigrationCreator::class)
51 217
            ->needs('$customStubPath')
52 217
            ->give(function () {
53
                return __DIR__ . '/../stubs';
54
            });
55
56 217
        $this->app->resolving(
57
            'db',
58 217
            function ($db) {
59 217
                $db->extend(
60
                    'arangodb',
61 217
                    function ($config, $name) {
62 217
                        $config['name'] = $name;
63 217
                        $connection = new Connection($config);
64 217
                        $connection->setSchemaGrammar(new SchemaGrammar());
65
66 217
                        return $connection;
67
                    }
68
                );
69
            }
70
        );
71
72 217
        $this->app->resolving(
73 217
            function () {
74 217
                if (class_exists('Illuminate\Foundation\AliasLoader')) {
75 217
                    $loader = \Illuminate\Foundation\AliasLoader::getInstance();
76 217
                    $loader->alias('Eloquent', 'LaravelFreelancerNL\Aranguent\Eloquent\Model');
77
                }
78
            }
79
        );
80
81 217
        $this->app->register('LaravelFreelancerNL\Aranguent\Providers\CommandServiceProvider');
82
    }
83
}
84