Passed
Push — master ( d68831...58f816 )
by Bruce Pinheiro de
04:28
created

PaymentInstrumentClient::getOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace BPCI\SumUp\Customer\PaymentInstrument;
4
5
use BPCI\SumUp\ContextInterface;
6
use BPCI\SumUp\Customer\CustomerInterface;
7
use BPCI\SumUp\OAuth\AccessToken;
8
use BPCI\SumUp\SumUpClientInterface;
9
use BPCI\SumUp\Traits\Client;
10
use BPCI\SumUp\Traits\ClientInterface;
11
use GuzzleHttp\Psr7\Response;
12
use Psr\Http\Message\ResponseInterface;
13
14
15
class PaymentInstrumentClient implements PaymentInstrumentClientInterface, ClientInterface
16
{
17
    use Client;
18
19
    protected $context;
20
    protected $options;
21
    protected $token;
22
    /**
23
     * @var CustomerInterface
24
     */
25
    protected $customer;
26
    /**
27
     * @var Response
28
     */
29
    protected $lastResponse;
30
31
    static function getScopes(): array
32
    {
33
        return [
34
            'payment_instruments'
35
        ];
36
    }
37
38
	/**
39
     * Retrieve a paymentInstrument from server and fill the $paymentInstrument Object with response.
40
	 *
41
	 */
42
    public function get(): array
43
    {
44
        $response = [];
45
        if ($this->request('get')) {
46
            $response = \GuzzleHttp\json_decode(
47
                $this->lastResponse->getBody(),
48
                true
49
            );
50
        };
51
52
        return $response;
53
	}
54
55
	/**
56
     * Delete an paymentInstrument from server.
57
	 *
58
     * @param PaymentInstrumentInterface $paymentInstrument
59
     * @return bool
60
	 */
61
    public function disable(PaymentInstrumentInterface $paymentInstrument):?bool
62
    {
63
        $uri = self::getEndPoint().'/'.$paymentInstrument->getToken();
0 ignored issues
show
Bug Best Practice introduced by
The method BPCI\SumUp\Customer\Paym...ntClient::getEndPoint() is not static, but was called statically. ( Ignorable by Annotation )

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

63
        $uri = self::/** @scrutinizer ignore-call */ getEndPoint().'/'.$paymentInstrument->getToken();
Loading history...
64
65
        return $this->request('delete', $paymentInstrument, $uri);
66
	}
67
68
	/**
69
	 * CheckoutClientInterface constructor.
70
	 * @param ContextInterface $context
71
     * @param array $options
72
     */
73
    public function __construct(ContextInterface $context, ?array $options = [])
74
	{
75
        $this->context = $context;
76
        $this->options = $options;
77
	}
78
79
	/**
80
	 * Return last response of client
81
	 * @return ResponseInterface
82
	 */
83
	function getLastResponse(): ResponseInterface
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
84
	{
85
        return $this->lastResponse;
86
	}
87
88
	/**
89
	 * return the context used to created the client.
90
	 * @return ContextInterface
91
	 */
92
	function getContext(): ContextInterface
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
93
	{
94
        return $this->context;
95
	}
96
97
    /**
98
     * @param PaymentInstrumentInterface $object
99
     * @param string|null $type
100
     * @return mixed
101
     */
102
    static function getBody($object, string $type = null)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
103
    {
104
        return null;
105
    }
106
107
    /**
108
     * @param ResponseInterface $response
109
     * @return SumUpClientInterface
110
     */
111
    function setLastResponse(ResponseInterface $response): SumUpClientInterface
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
112
    {
113
        $this->lastResponse = $response;
0 ignored issues
show
Documentation Bug introduced by
$response is of type Psr\Http\Message\ResponseInterface, but the property $lastResponse was declared to be of type GuzzleHttp\Psr7\Response. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
114
115
        return $this;
116
    }
117
118
    /**
119
     * @return array
120
     */
121
    function getOptions(): array
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
122
    {
123
        return $this->options;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->options could return the type null which is incompatible with the type-hinted return array. Consider adding an additional type-check to rule them out.
Loading history...
124
    }
125
126
    /**
127
     * @return string
128
     */
129
    function getEndPoint(): string
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
130
    {
131
        return 'customers/'.$this->customer->getCustomerId().'/payment-instruments';
132
    }
133
134
    /**
135
     * @param AccessToken $token
136
     * @return SumUpClientInterface
137
     */
138
    function setToken(AccessToken $token): SumUpClientInterface
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
139
    {
140
        $this->token = $token;
141
142
        return $this;
143
    }
144
145
    /**
146
     * @return AccessToken
147
     */
148
    function getToken():? AccessToken
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
149
    {
150
        return $this->token;
151
    }
152
153
    /**
154
     * @param CustomerInterface $customer
155
     * @return PaymentInstrumentClientInterface
156
     */
157
    public function setCustomer(CustomerInterface $customer): PaymentInstrumentClientInterface
158
    {
159
        $this->customer = $customer;
160
161
        return $this;
162
    }
163
164
    /**
165
     * @return CustomerInterface
166
     */
167
    public function getCustomer(): CustomerInterface
168
    {
169
        return $this->customer;
170
	}
171
}
172