Completed
Pull Request — master (#71)
by Olatunbosun
16:04
created

PaystackServiceProvider::provides()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
c 0
b 0
f 0
rs 9.9666
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Laravel Paystack package.
7
 *
8
 * (c) Prosper Otemuyiwa <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Unicodeveloper\Paystack;
15
16
use Illuminate\Container\Container;
17
use Illuminate\Foundation\Application as LaravelApp;
18
use Illuminate\Support\ServiceProvider;
19
use Xeviant\Paystack\Client;
20
use Laravel\Lumen\Application as LumenApp;
21
22
class PaystackServiceProvider extends ServiceProvider
23
{
24
25
    /*
26
    * Indicates if loading of the provider is deferred.
27
    *
28
    * @var bool
29
    */
30
    protected $defer = false;
31
32
    /**
33
    * Publishes all the config file this package needs to function
34
    */
35
    public function boot()
36
    {
37
        $this->setupConfig();
38
    }
39
40
    /**
41
     * Sets up Paystack configuration file
42
     */
43
    protected function setupConfig()
44
    {
45
        $config = realpath($raw = __DIR__.'/../resources/config/paystack.php') ?: $raw;
46
47
        if ($this->app instanceof LaravelApp && $this->app->runningInConsole()) {
48
            $this->publishes([
49
                $config => config_path('paystack.php')
50
            ]);
51
        } elseif ($this->app instanceof LumenApp) {
0 ignored issues
show
Bug introduced by
The class Laravel\Lumen\Application does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
52
            $this->app->configure('paystack');
53
        }
54
55
        $this->mergeConfigFrom($config, 'paystack');
56
    }
57
58
    /**
59
    * Register the application services.
60
    */
61
    public function register()
62
    {
63
        $this->app->bind('laravel-paystack', function () {
64
            return new Paystack;
65
        });
66
67
        $this->registerPaystackFactory()
68
            ->registerPaystackManager()
69
            ->registerCoreBindings();
70
    }
71
72
    /**
73
     * Registers the Paystack factory
74
     *
75
     * @return $this
76
     */
77
    protected function registerPaystackFactory()
78
    {
79
        $this->app->singleton('paystack.factory', function (Container $container) {
80
            $cache = $container['cache'];
81
82
            return new PaystackFactory($cache);
83
        });
84
85
        $this->app->alias('paystack.factory', PaystackFactory::class);
86
87
        return $this;
88
    }
89
90
    /**
91
     * Registers Paystack manager
92
     *
93
     * @return $this
94
     */
95
    protected function registerPaystackManager()
96
    {
97
        $this->app->singleton('paystack', function (Container $container) {
98
            $config = $container['config'];
99
            $factory = $container['paystack.factory'];
100
101
            return new PaystackManager($config, $factory);
102
        });
103
104
        $this->app->alias('paystack', PaystackManager::class);
105
106
        return $this;
107
    }
108
109
    /**
110
     * Registers the Core Paystack Binding
111
     *
112
     * @return $this
113
     */
114
    protected function registerCoreBindings()
115
    {
116
        $this->app->bind('paystack.connection', function (Container $container) {
117
           $manager = $container['paystack'];
118
119
           return $manager->connection();
120
        });
121
122
        $this->app->alias('paystack.connection', Client::class);
123
124
        return $this;
125
    }
126
127
    /**
128
    * Get the services provided by the provider
129
    * @return array
130
    */
131
    public function provides()
132
    {
133
        return [
134
            'paystack',
135
            'paystack.factory',
136
            'laravel-paystack',
137
            'paystack.connection',
138
        ];
139
    }
140
}
141