getIntegrationPackageName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace DansMaCulotte\Contentful;
4
5
use Contentful\Core\Api\IntegrationInterface;
6
use Contentful\Delivery\Client;
7
use Contentful\Delivery\ClientOptions;
8
use Illuminate\Contracts\Support\DeferrableProvider;
9
use Illuminate\Foundation\Application;
10
use Illuminate\Support\ServiceProvider;
11
12
class ContentfulServiceProvider extends ServiceProvider implements IntegrationInterface, DeferrableProvider
13
{
14
    /**
15
     * Bootstrap the application services.
16
     */
17
    public function boot()
18
    {
19
        $this->mergeConfigFrom(__DIR__.'/../config/contentful.php', 'contentful');
20
21
        $this->publishes([
22
            __DIR__.'/../config/contentful.php' => config_path('contentful.php'),
23
        ]);
24
    }
25
26
    /**
27
     * Register the service provider.
28
     */
29
    public function register()
30
    {
31
        $this->app->singleton(Client::class, function ($app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
32
            $config = config('contentful', []);
33
34
            $options = new ClientOptions();
35
            if (is_bool($config['preview']) && $config['preview']) {
36
                $options->usingPreviewApi();
37
            }
38
39
            $locale = app()->getLocale();
40
            if ($config['defaultLocale']) {
41
                $locale = $config['defaultLocale'];
42
            }
43
            $options->withDefaultLocale($locale);
44
45
            $client = new Client(
46
                $config['deliveryToken'],
47
                $config['space'],
48
                $config['environment'],
49
                $options
50
            );
51
            $client->useIntegration($this);
52
53
            return $client;
54
        });
55
56
        $this->app->alias(Client::class, 'contentful');
57
    }
58
59
    /**
60
     * Returns the name of the current integration.
61
     * This value must be the one that is sent as part of
62
     * the "X-Contentful-User-Agent" header to the API.
63
     *
64
     * @return string
65
     */
66
    public function getIntegrationName(): string
67
    {
68
        return 'laravel-contentful';
69
    }
70
71
    /**
72
     * Returns the package name of the current integration.
73
     * This value must be the one defined in the "composer.json" file.
74
     *
75
     * @return string
76
     */
77
    public function getIntegrationPackageName(): string
78
    {
79
        return 'dansmaculotte/laravel-contentful';
80
    }
81
82
    /**
83
     * Get the services provided by the provider.
84
     *
85
     * @return array
86
     */
87
    public function provides()
88
    {
89
        return ['contentful'];
90
    }
91
}
92