Completed
Push — master ( 66cdb5...bfea69 )
by Maxime
04:50
created

ServiceProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 10

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
dl 0
loc 101
ccs 30
cts 40
cp 0.75
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A provides() 0 13 1
A boot() 0 8 1
A register() 0 13 2
A registerCommands() 0 36 1
1
<?php
2
3
namespace Distilleries\Contentful;
4
5
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
6
7
class ServiceProvider extends BaseServiceProvider
8
{
9
    /**
10
     * Package Laravel specific internal name.
11
     *
12
     * @var string
13
     */
14
    protected $package = 'contentful';
15
16
    /**
17
     * {@inheritdoc}
18
     */
19
    public function provides(): array
20
    {
21
        return [
22
            'command.contentful.model',
23
            'command.contentful.migration',
24
            'command.contentful.sync',
25
            'command.contentful.sync-data',
26
            'command.contentful.sync-flatten',
27
            'command.contentful.sync-locales',
28
            'command.contentful.import-clean',
29
            'command.contentful.import-publish',
30
        ];
31
    }
32
33
    /**
34
     * Bootstrap any application services.
35
     *
36
     * @return void
37
     */
38 36
    public function boot()
39
    {
40 36
        $this->publishes([
41 36
            __DIR__ . '/../../config/config.php' => base_path('config/' . $this->package . '.php'),
42 36
        ], 'config');
43
44 36
        $this->loadMigrationsFrom(__DIR__ . '/../../database/migrations/');
45
    }
46
47
    /**
48
     * Register any application services.
49
     *
50
     * @return void
51
     */
52 36
    public function register()
53
    {
54 36
        $this->mergeConfigFrom(__DIR__ . '/../../config/config.php', $this->package);
55
56 36
        $this->app->bind(Api\DeliveryApi::class, Api\Delivery\Cached::class);
57 36
        $this->app->bind(Api\ManagementApi::class, Api\Management\Api::class);
58 36
        $this->app->bind(Api\SyncApi::class, Api\Sync\Api::class);
59 36
        $this->app->bind(Api\UploadApi::class, Api\Upload\Api::class);
60
61 36
        if ($this->app->runningInConsole()) {
62 36
            $this->registerCommands();
63
        }
64
    }
65
66
    /**
67
     * Register Artisan commands.
68
     *
69
     * @return void
70
     */
71 36
    private function registerCommands()
72
    {
73
        $this->app->singleton('command.contentful.model', function () {
74
            return new Commands\Generators\Models(app(Api\ManagementApi::class));
75 36
        });
76
        $this->app->singleton('command.contentful.migration', function () {
77
            return new Commands\Generators\Migrations(app(Api\ManagementApi::class));
78 36
        });
79
        $this->app->singleton('command.contentful.sync', function () {
80
            return new Commands\Sync\Sync;
81 36
        });
82
        $this->app->singleton('command.contentful.sync-data', function () {
83
            return new Commands\Sync\SyncData(app(Api\SyncApi::class));
84 36
        });
85
        $this->app->singleton('command.contentful.sync-flatten', function () {
86
            return new Commands\Sync\SyncFlatten;
87 36
        });
88
        $this->app->singleton('command.contentful.sync-locales', function () {
89
            return new Commands\Sync\SyncLocales(app(Api\ManagementApi::class));
90 36
        });
91
        $this->app->singleton('command.contentful.import-clean', function () {
92
            return new Commands\Import\ImportClean(app(Api\ManagementApi::class));
93 36
        });
94
        $this->app->singleton('command.contentful.import-publish', function () {
95
            return new Commands\Import\ImportPublish(app(Api\ManagementApi::class));
96 36
        });
97
98 36
        $this->commands('command.contentful.model');
99 36
        $this->commands('command.contentful.migration');
100 36
        $this->commands('command.contentful.sync');
101 36
        $this->commands('command.contentful.sync-data');
102 36
        $this->commands('command.contentful.sync-flatten');
103 36
        $this->commands('command.contentful.sync-locales');
104 36
        $this->commands('command.contentful.import-clean');
105 36
        $this->commands('command.contentful.import-publish');
106
    }
107
}
108