Completed
Pull Request — master (#44)
by 'Tunde
10:50
created

PaystackServiceProvider::setSecretToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Laravel Paystack package.
5
 *
6
 * (c) Prosper Otemuyiwa <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Unicodeveloper\Paystack;
13
14
use GuzzleHttp\Client;
15
use Illuminate\Support\ServiceProvider;
16
17
class PaystackServiceProvider extends ServiceProvider
18
{
19
20
    /*
21
    * Indicates if loading of the provider is deferred.
22
    *
23
    * @var bool
24
    */
25
    protected $defer = false;
26
27
    /**
28
     * Placeholder for base URL.
29
     * 
30
     * @var string
31
     */
32
    protected $baseUrl;
33
34
    /**
35
     * Placeholder for secret key.
36
     * 
37
     * @var string
38
     */
39
    protected $secretKey;
40
41
    /**
42
     * Placeholder for GuzzleHttp\Client.
43
     * 
44
     * @var \GuzzleHttp\Cient
45
     */
46
    protected $client;
47
48
    /**
49
    * Publishes all the config file this package needs to function
50
    */
51
    public function boot()
52
    {
53
        $config = realpath(__DIR__.'/../resources/config/paystack.php');
54
55
        $this->publishes([
56
            $config => config_path('paystack.php')
57
        ]);
58
    }
59
60
    /**
61
    * Register the application services.
62
    */
63
    public function register()
64
    {
65
        $this->bootstrapConfig();
66
67
        $this->app->singleton('laravel-paystack', function ($app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed.

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

Loading history...
68
69
            return new Paystack($this->client);
70
71
        });
72
    }
73
74
    /**
75
    * Get the services provided by the provider
76
    * @return array
77
    */
78
    public function provides()
79
    {
80
        return ['laravel-paystack'];
81
    }
82
83
    /**
84
     * Bootstraps configuration if configuration file exists.
85
     * 
86
     * @return void
87
     */
88
    protected function bootstrapConfig() 
89
    {    
90
        $this->setDependencies();
91
        $this->setClient();
92
    }
93
94
    /**
95
     * Called upon to set required meta dependencies.
96
     */
97
    protected function setDependencies()
98
    {
99
        $this->setBaseUrl();
100
101
        $this->setSecretToken();
102
    }
103
104
    /**
105
     * Set the base url from conig.
106
     */
107
    protected function setBaseUrl()
108
    {
109
        $this->baseUrl = $this->app["config"]->get("paystack.paymentUrl");
110
    }
111
112
    /**
113
     * Set the base url from conig.
114
     */
115
    protected function setSecretToken()
116
    {
117
        $this->secretKey = $this->app["config"]->get("paystack.secretKey");
118
    }
119
120
    /**
121
     * Set guzzle client.
122
     */
123
    protected function setClient()
124
    {
125
        $this->client = new Client([
0 ignored issues
show
Documentation Bug introduced by
It seems like new \GuzzleHttp\Client(a...> 'application/json'))) of type object<GuzzleHttp\Client> is incompatible with the declared type object<GuzzleHttp\Cient> of property $client.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
126
            "base_uri" => $this->baseUrl,
127
            'headers' => [
128
                'Authorization' => "Bearer {$this->secretKey}",
129
                'Content-Type'  => 'application/json',
130
                'Accept'        => 'application/json'
131
            ],
132
        ]);
133
    }
134
}
135