AbstractContentfulSyncServiceProvider   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 47
Duplicated Lines 21.28 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 10
loc 47
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
registerContentfulSyncServiceBindings() 0 1 ?
A register() 10 28 1
A boot() 0 3 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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