NetgsmServiceProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 17
c 1
b 0
f 0
dl 0
loc 41
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 12 2
A register() 0 18 2
1
<?php
2
3
namespace TarfinLabs\Netgsm;
4
5
use GuzzleHttp\Client;
6
use Illuminate\Support\ServiceProvider;
7
use TarfinLabs\Netgsm\Exceptions\InvalidConfiguration;
8
9
class NetgsmServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Bootstrap the application services.
13
     */
14
    public function boot()
15
    {
16
        $this->loadTranslationsFrom(dirname(__DIR__).'/resources/lang', 'netgsm');
17
18
        if ($this->app->runningInConsole()) {
19
            $this->publishes([
20
                dirname(__DIR__).'/resources/lang' => resource_path('lang/vendor/netgsm'),
21
            ]);
22
23
            $this->publishes([
24
                __DIR__.'/../config/config.php' => config_path('netgsm.php'),
25
            ], 'config');
26
        }
27
    }
28
29
    /**
30
     * Register the application services.
31
     */
32
    public function register()
33
    {
34
        // Automatically apply the package configuration
35
        $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'netgsm');
36
37
        $this->app->singleton(Netgsm::class, function ($app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed. ( Ignorable by Annotation )

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

37
        $this->app->singleton(Netgsm::class, function (/** @scrutinizer ignore-unused */ $app) {

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

Loading history...
38
            $config = config('netgsm');
39
40
            if (is_null($config)) {
41
                throw InvalidConfiguration::configurationNotSet();
42
            }
43
44
            $client = new Client([
45
                'base_uri' => $config['defaults']['base_uri'],
46
                'timeout'  => $config['defaults']['timeout'],
47
            ]);
48
49
            return new Netgsm($client, $config['credentials'], $config['defaults']);
50
        });
51
    }
52
}
53