Gateway   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 118
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 118
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setOptions() 0 4 1
A getOptions() 0 4 1
A getOption() 0 4 1
A getDefaultOptions() 0 4 1
getName() 0 1 ?
A createRequest() 0 6 1
A getHttpClient() 0 8 2
A setHttpClient() 0 6 1
1
<?php
2
3
namespace CryptoMarkets\Common;
4
5
abstract class Gateway implements GatewayInterface
6
{
7
    /**
8
     * The HTTP client instance.
9
     *
10
     * @var \CryptoMarkets\Common\Client
11
     */
12
    protected $httpClient;
13
14
    /**
15
     * The gateway's options.
16
     *
17
     * @var array
18
     */
19
    protected $options = [];
20
21
    /**
22
     * Create a new Gateway instance.
23
     *
24
     * @param  array  $options
25
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
26
     */
27
    public function __construct(array $options = [])
28
    {
29
        $this->setOptions($options);
30
    }
31
32
    /**
33
     * Merge the custom options with the defaults.
34
     *
35
     * @param  array  $options
36
     * @return void
37
     */
38
    public function setOptions(array $options = [])
39
    {
40
        $this->options = array_replace($this->getDefaultOptions(), $options);
41
    }
42
43
    /**
44
     * Get the options.
45
     *
46
     * @return array
47
     */
48
    public function getOptions()
49
    {
50
        return $this->options;
51
    }
52
53
    /**
54
     * et the specified option value (if any).
55
     *
56
     * @param  string  $key
57
     * @param  mixed  $default
58
     * @return mixed
59
     */
60
    public function getOption($key, $default = null)
0 ignored issues
show
Unused Code introduced by
The parameter $default 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...
61
    {
62
        return $this->options[$key];
63
    }
64
65
    /**
66
     * Get the default options.
67
     *
68
     * @return array
69
     */
70
    public function getDefaultOptions()
71
    {
72
        return [];
73
    }
74
75
    /**
76
     * Get the gateway name.
77
     *
78
     * @return string
79
     */
80
    abstract public function getName();
81
82
    /**
83
     * Create a new request object.
84
     *
85
     * @param  string  $class
86
     * @param  array  $params
87
     * @return \CryptoMarkets\Common\Http\Request
88
     */
89
    public function createRequest($class, array $params = [])
90
    {
91
        $instance = new $class($this->getHttpClient());
92
93
        return $instance->configure(array_replace($this->getOptions(), $params));
94
    }
95
96
    /**
97
     * Get a instance of the HTTP client.
98
     *
99
     * @return \CryptoMarkets\Common\Client
100
     */
101
    public function getHttpClient()
102
    {
103
        if (is_null($this->httpClient)) {
104
            $this->setHttpClient(new Client);
105
        }
106
107
        return $this->httpClient;
108
    }
109
110
    /**
111
     * Set the HTTP client instance.
112
     *
113
     * @param  \CryptoMarkets\Common\Client  $client
114
     * @return $this
115
     */
116
    public function setHttpClient(Client $client)
117
    {
118
        $this->httpClient = $client;
119
120
        return $this;
121
    }
122
}
123