DhlParcelServiceProvider   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
eloc 18
c 2
b 0
f 0
dl 0
loc 69
ccs 26
cts 26
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A provides() 0 5 1
A register() 0 8 1
A registerPublishing() 0 6 2
A registerDhlClient() 0 7 1
A registerDhlAdapter() 0 7 1
1
<?php
2
3
namespace Mvdnbrk\Laravel;
4
5
use Illuminate\Contracts\Support\DeferrableProvider;
6
use Illuminate\Support\ServiceProvider;
7
use Mvdnbrk\DhlParcel\Client;
8
use Psr\Container\ContainerInterface;
9
10
class DhlParcelServiceProvider extends ServiceProvider implements DeferrableProvider
11
{
12
    /**
13
     * Register the application services.
14
     *
15
     * @return void
16
     */
17 16
    public function register()
18
    {
19 16
        $this->mergeConfigFrom(__DIR__.'/../config/dhlparcel.php', 'dhlparcel');
20
21 16
        $this->registerDhlClient();
22 16
        $this->registerDhlAdapter();
23
24 16
        $this->registerPublishing();
25 16
    }
26
27
    /**
28
     * Register the DHL Parcel Client.
29
     *
30
     * @return void
31
     */
32 16
    protected function registerDhlClient()
33
    {
34 8
        $this->app->singleton(Client::class, function () {
35 16
            return (new Client)->setUserId(config('dhlparcel.id'))->setApiKey(config('dhlparcel.secret'));
36 16
        });
37
38 16
        $this->app->alias(Client::class, 'dhlparcel');
39 16
    }
40
41
    /**
42
     * Register the DHL Parcel Client Adapter.
43
     *
44
     * @return void
45
     */
46 16
    protected function registerDhlAdapter()
47
    {
48 8
        $this->app->singleton(DhlParcelClientAdapter::class, function (ContainerInterface $container) {
49 12
            return new DhlParcelClientAdapter($container->get('dhlparcel'));
50 16
        });
51
52 16
        $this->app->alias(DhlParcelClientAdapter::class, 'dhlparcel.adapter');
53 16
    }
54
55
    /**
56
     * Register the package's publishable resources.
57
     *
58
     * @return void
59
     */
60 16
    protected function registerPublishing()
61
    {
62 16
        if ($this->app->runningInConsole()) {
63 16
            $this->publishes([
64 16
                __DIR__.'/../config/dhlparcel.php' => config_path('dhlparcel.php'),
65 16
            ], 'dhlparcel-config');
66
        }
67 16
    }
68
69
    /**
70
     * Get the services provided by the provider.
71
     *
72
     * @return array
73
     */
74 4
    public function provides()
75
    {
76
        return [
77 4
            'dhlparcel',
78
            'dhlparcel.adapter',
79
        ];
80
    }
81
}
82