Passed
Push — master ( 519b06...806fd9 )
by Bruce Pinheiro de
02:47
created

PaymentInstrumentClient::setToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 9.4285
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 2
    static function getScopes(): array
32
    {
33
        return [
34 2
            'payment_instruments'
35
        ];
36
    }
37
38
	/**
39
     * Retrieve a paymentInstrument from server and fill the $paymentInstrument Object with response.
40
	 *
41
	 */
42 1
    public function get(): array
43
    {
44 1
        $response = [];
45 1
        if ($this->request('get')) {
46 1
            $response = \GuzzleHttp\json_decode(
47 1
                $this->lastResponse->getBody(),
48 1
                true
49
            );
50
        };
51
52 1
        return $response;
53
	}
54
55
	/**
56
     * Delete an paymentInstrument from server.
57
	 *
58
     * @param PaymentInstrumentInterface $paymentInstrument
59
     * @return bool
60
	 */
61 1
    public function disable(PaymentInstrumentInterface $paymentInstrument):?bool
62
    {
63 1
        $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 1
        return $this->request('delete', $paymentInstrument, $uri);
66
	}
67
68
	/**
69
	 * CheckoutClientInterface constructor.
70
	 * @param ContextInterface $context
71
     * @param array $options
72
     */
73 2
    public function __construct(ContextInterface $context, ?array $options = [])
74
	{
75 2
        $this->context = $context;
76 2
        $this->options = $options;
77 2
	}
78
79
	/**
80
	 * Return last response of client
81
	 * @return ResponseInterface
82
	 */
83 2
	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 2
        return $this->lastResponse;
86
	}
87
88
	/**
89
	 * return the context used to created the client.
90
	 * @return ContextInterface
91
	 */
92 2
	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 2
        return $this->context;
95
	}
96
97
    /**
98
     * @param PaymentInstrumentInterface $object
99
     * @param string|null $type
100
     * @return mixed
101
     */
102 1
    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 1
        return null;
105
    }
106
107
    /**
108
     * @param ResponseInterface $response
109
     * @return SumUpClientInterface
110
     */
111 2
    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 2
        $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 2
        return $this;
116
    }
117
118
    /**
119
     * @return array
120
     */
121 2
    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 2
        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 2
    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 2
        return 'customers/'.$this->customer->getCustomerId().'/payment-instruments';
132
    }
133
134
    /**
135
     * @param AccessToken $token
136
     * @return SumUpClientInterface
137
     */
138 2
    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 2
        $this->token = $token;
141
142 2
        return $this;
143
    }
144
145
    /**
146
     * @return AccessToken
147
     */
148 2
    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 2
        return $this->token;
151
    }
152
153
    /**
154
     * @param CustomerInterface $customer
155
     * @return PaymentInstrumentClientInterface
156
     */
157 2
    public function setCustomer(CustomerInterface $customer): PaymentInstrumentClientInterface
158
    {
159 2
        $this->customer = $customer;
160
161 2
        return $this;
162
    }
163
164
    /**
165
     * @return CustomerInterface
166
     */
167
    public function getCustomer(): CustomerInterface
168
    {
169
        return $this->customer;
170
	}
171
}
172