TransactionStatusResponse::__construct()   A
last analyzed

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
c 0
b 0
f 0
nc 1
nop 3
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Omnipay\IcepayPayments\Message;
4
5
use Omnipay\Common\Message\RequestInterface;
6
7
/**
8
 * The response after getting the transaction status at Icepay.
9
 * For this response, we check the response (statusCode) of the payment transaction at Icepay.
10
 */
11
class TransactionStatusResponse extends AbstractResponse
12
{
13
    /**
14
     * @var int
15
     */
16
    private $statusCode;
17
18
    /**
19
     * TransactionStatusResponse constructor.
20
     *
21
     * @param RequestInterface $request
22
     * @param mixed            $data
23
     * @param int              $statusCode
24
     */
25 4
    public function __construct(RequestInterface $request, $data, int $statusCode)
26
    {
27 4
        parent::__construct($request, $data);
28
29 4
        $this->statusCode = $statusCode;
30 4
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function getCode()
36
    {
37
        return $this->statusCode;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 2
    public function isSuccessful(): bool
44
    {
45 2
        return $this->statusCode === 200;
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 1
    public function isCancelled(): bool
52
    {
53 1
        return isset($this->data['status']) && $this->data['status'] === self::RESPONSE_STATUS_CANCELLED;
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59 1
    public function getTransactionReference(): ?string
60
    {
61 1
        return isset($this->data['id']) ? $this->data['id'] : $this->request->getTransactionReference();
62
    }
63
}
64