AbstractContentfulSyncServiceProvider::boot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Digia\Lumen\ContentfulSync\Providers;
4
5
use Digia\Lumen\ContentfulSync\Console\Commands\SyncAssetsCommand;
6
use Digia\Lumen\ContentfulSync\Console\Commands\SyncContentsCommand;
7
use Digia\Lumen\ContentfulSync\Contracts\ContentfulSyncServiceContract;
8
use Digia\Lumen\ContentfulSync\Http\Middleware\WebhookAuthenticationMiddleware;
9
use Illuminate\Support\ServiceProvider;
10
use Jalle19\Laravel\LostInterfaces\Providers\ServiceProvider as ServiceProviderInterface;
11
use Laravel\Lumen\Application;
12
use Nord\Lumen\Contentful\ContentfulServiceContract;
13
14
/**
15
 * Class AbstractContentfulSyncServiceProvider
16
 * @package Digia\Lumen\ContentfulSync\Providers
17
 */
18
abstract class AbstractContentfulSyncServiceProvider extends ServiceProvider implements ServiceProviderInterface
19
{
20
21
    /**
22
     * @param Application $app
23
     */
24
    abstract protected function registerContentfulSyncServiceBindings(Application $app);
25
26
    /**
27
     * @inheritDoc
28
     */
29
    public function register(): void
30
    {
31
        app()->configure('contentfulSync');
32
33
        // Configure how ContentfulSyncServiceContract should be built
34
        $this->registerContentfulSyncServiceBindings(app());
35
36
        // Configure how commands should be built
37 View Code Duplication
        app()->bind(SyncAssetsCommand::class, function (Application $app) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
38
            return new SyncAssetsCommand(config('contentfulSync.content_types'),
39
                $app->make(ContentfulServiceContract::class),
40
                $app->make(ContentfulSyncServiceContract::class));
41
        });
42
43 View Code Duplication
        app()->bind(SyncContentsCommand::class, function (Application $app) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44
            return new SyncContentsCommand(config('contentfulSync.content_types'),
45
                $app->make(ContentfulServiceContract::class),
46
                $app->make(ContentfulSyncServiceContract::class));
47
        });
48
49
        // Configure how middleware should be built
50
        app()->bind(WebhookAuthenticationMiddleware::class, function () {
51
            $expectedUsername = config('contentfulSync.webhookUsername');
52
            $expectedPassword = config('contentfulSync.webhookPassword');
53
54
            return new WebhookAuthenticationMiddleware($expectedUsername, $expectedPassword);
55
        });
56
    }
57
58
    /**
59
     * @inheritDoc
60
     */
61
    public function boot(): void
62
    {
63
    }
64
}
65