MoipServiceProvider   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 5
dl 0
loc 73
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 4 1
A register() 0 6 1
A provides() 0 4 1
A handleConfigs() 0 12 2
A isLumen() 0 4 1
A getHomologated() 0 4 2
1
<?php
2
3
namespace Artesaos\Moip\Providers;
4
5
use Artesaos\Moip\Moip;
6
use Illuminate\Support\ServiceProvider;
7
use Moip\Moip as Api;
8
use Moip\Auth\BasicAuth;
9
10
/**
11
 * Class MoipServiceProvider.
12
 *
13
 * @package Artesaos\Moip\Providers
14
 */
15
class MoipServiceProvider extends ServiceProvider
16
{
17
    /**
18
     * Indicates if loading of the provider is deferred.
19
     *
20
     * @var bool
21
     */
22
    protected $defer = true;
23
24
    /**
25
     * Bootstrap the application events.
26
     */
27
    public function boot()
28
    {
29
        $this->handleConfigs();
30
    }
31
32
    /**
33
     * Register the service provider.
34
     */
35
    public function register()
36
    {
37
        $this->app->singleton('moip', function(){
38
            return new Moip(new Api(new BasicAuth($this->app->make('config')->get('moip.credentials.token'), $this->app->make('config')->get('moip.credentials.key')), $this->getHomologated()));
39
        });
40
    }
41
42
    /**
43
     * Get the services provided by the provider.
44
     *
45
     * @return array
46
     */
47
    public function provides()
48
    {
49
        return ['moip'];
50
    }
51
52
    /**
53
     * Publishes and Merge configs.
54
     */
55
    public function handleConfigs()
56
    {
57
        $config_file = __DIR__.'/../../config/moip.php';
58
59
        if ($this->isLumen()) {
60
            $this->app->configure('moip');
0 ignored issues
show
Bug introduced by
The method configure() does not exist on Illuminate\Contracts\Foundation\Application. Did you maybe mean registerConfiguredProviders()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
61
        } else {
62
            $this->publishes([$config_file => config_path('moip.php')]);
63
        }
64
65
        $this->mergeConfigFrom($config_file, 'moip');
66
    }
67
68
    /**
69
     * Checks if the application is Lumen.
70
     *
71
     * @return bool
72
     */
73
    private function isLumen()
74
    {
75
        return true === str_contains($this->app->version(), 'Lumen');
0 ignored issues
show
Deprecated Code introduced by
The function str_contains() has been deprecated with message: Str::contains() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
76
    }
77
78
    /**
79
     * Get endpoint of request.
80
     *
81
     * @return string
82
     */
83
    private function getHomologated()
84
    {
85
        return $this->app->make('config')->get('moip.homologated') === true ? Api::ENDPOINT_PRODUCTION : Api::ENDPOINT_SANDBOX;
86
    }
87
}
88