Passed
Push — master ( 2011df...6dca79 )
by Mark van den
02:36
created

DhlParcelServiceProvider::provides()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 5
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 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
9
class DhlParcelServiceProvider extends ServiceProvider implements DeferrableProvider
10
{
11
    /**
12
     * Register the application services.
13
     *
14
     * @return void
15
     */
16 12
    public function register()
17
    {
18 12
        $this->mergeConfigFrom(__DIR__.'/../config/dhlparcel.php', 'dhlparcel');
19
20 12
        $this->registerDhlClient();
21 12
        $this->registerDhlAdapter();
22
23 12
        $this->registerPublishing();
24 12
    }
25
26
    /**
27
     * Register the DHL Parcel Client.
28
     *
29
     * @return void
30
     */
31 12
    protected function registerDhlClient()
32
    {
33
        $this->app->singleton(Client::class, function () {
34 12
            return (new Client)->setUserId(config('dhlparcel.id'))->setApiKey(config('dhlparcel.secret'));
35 12
        });
36
37 12
        $this->app->alias(Client::class, 'dhlparcel');
38 12
    }
39
40
    /**
41
     * Register the DHL Parcel Client Adapter.
42
     *
43
     * @return void
44
     */
45 12
    protected function registerDhlAdapter()
46
    {
47
        $this->app->singleton(DhlParcelClientAdapter::class, function () {
48 8
            return new DhlParcelClientAdapter(app('dhlparcel'));
0 ignored issues
show
Bug introduced by
It seems like app('dhlparcel') can also be of type Illuminate\Contracts\Foundation\Application; however, parameter $client of Mvdnbrk\Laravel\DhlParce...tAdapter::__construct() does only seem to accept Mvdnbrk\DhlParcel\Client, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

48
            return new DhlParcelClientAdapter(/** @scrutinizer ignore-type */ app('dhlparcel'));
Loading history...
49 12
        });
50
51 12
        $this->app->alias(DhlParcelClientAdapter::class, 'dhlparcel.adapter');
52 12
    }
53
54
    /**
55
     * Register the package's publishable resources.
56
     *
57
     * @return void
58
     */
59 12
    protected function registerPublishing()
60
    {
61 12
        if ($this->app->runningInConsole()) {
62 12
            $this->publishes([
63 12
                __DIR__.'/../config/dhlparcel.php' => config_path('dhlparcel.php'),
64 12
            ], 'dhlparcel-config');
65
        }
66 12
    }
67
68
    /**
69
     * Get the services provided by the provider.
70
     *
71
     * @return array
72
     */
73 4
    public function provides()
74
    {
75
        return [
76 4
            'dhlparcel',
77
            'dhlparcel.adapter',
78
        ];
79
    }
80
}
81