Passed
Push — master ( 8c743d...154964 )
by Eudald
10:11
created

GocardlessServiceProvider   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 62
rs 10
c 0
b 0
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 5 1
A provides() 0 4 1
A boot() 0 16 2
A registerGocardless() 0 12 3
1
<?php
2
/**
3
 * Part of the GoCardless Pro PHP Client package integration for Laravel
4
 *
5
 * NOTICE OF LICENSE
6
 *
7
 * Licensed under the MIT License.
8
 *
9
 * This source file is subject to the MIT License that is
10
 * bundled with this package in the LICENSE file.
11
 *
12
 * @package    Gocardless Laravel
13
 * @version    0.1.0
14
 * @author     Nested.net
15
 * @license    MIT
16
 * @link       https://nested.net
17
 */
18
19
namespace Nestednet\Gocardless;
20
21
use GoCardlessPro\Client;
22
use Illuminate\Support\Facades\Route;
23
use Illuminate\Support\ServiceProvider;
24
25
class GocardlessServiceProvider extends ServiceProvider
26
{
27
28
    /**
29
     * {@inheritDoc}
30
     */
31
    public function boot()
32
    {
33
        $this->publishes([
34
            __DIR__.'/config/gocardless.php' => config_path('gocardless.php'),
0 ignored issues
show
Bug introduced by
The function config_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

34
            __DIR__.'/config/gocardless.php' => /** @scrutinizer ignore-call */ config_path('gocardless.php'),
Loading history...
35
        ], 'config');
36
37
        if (! class_exists('CreateGocardlessWebhookClassTable')) {
38
            $timestamp = date('Y_m_d_His', time());
39
40
            $this->publishes([
41
                __DIR__.'/../database/migrations/create_gocardless_webhook_calls_table.php.stub' => database_path('migrations/'.$timestamp.'_create_gocardless_webhook_calls_table.php'),
0 ignored issues
show
Bug introduced by
The function database_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

41
                __DIR__.'/../database/migrations/create_gocardless_webhook_calls_table.php.stub' => /** @scrutinizer ignore-call */ database_path('migrations/'.$timestamp.'_create_gocardless_webhook_calls_table.php'),
Loading history...
42
            ], 'migrations');
43
        }
44
45
        Route::macro('gocardlessWebhooks', function ($url) {
46
            return Route::post($url, '\Nestednet\Gocardless\Controllers\GocardlessWebhookController');
47
        });
48
    }
49
50
    /**
51
     * {@inheritDoc} d
52
     */
53
    public function register()
54
    {
55
        $this->mergeConfigFrom(__DIR__ . '/config/gocardless.php', 'gocardless');
56
57
        $this->registerGocardless();
58
    }
59
60
    /**
61
     * {@inheritDoc}
62
     */
63
    public function provides()
64
    {
65
        return [
66
            'gocardless',
67
        ];
68
    }
69
70
    /**
71
     * Register the Gocardless API class.
72
     *
73
     * @return void
74
     */
75
    protected function registerGocardless()
76
    {
77
        $this->app->singleton('gocardless', function ($app) {
78
            $config = $app['config']->get('gocardless');
79
            $token = isset($config['token']) ? $config['token'] : null;
80
            $environment = isset($config['environment']) ? $config['environment'] : null;
81
            return new Client( array (
82
                'access_token' => $token,
83
                'environment' => $environment
84
            ));
85
        });
86
        $this->app->alias('gocardless', 'GoCardlessPro\Client');
87
    }
88
}