Passed
Pull Request — master (#20)
by Kiet
02:29
created

FetchTransactionResponse::__construct()   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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
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
declare(strict_types=1);
4
5
namespace Omnipay\IcepayPayments\Message;
6
7
use Omnipay\Common\Message\RequestInterface;
8
use Symfony\Component\HttpFoundation\Response;
9
10
class FetchTransactionResponse extends AbstractResponse
11
{
12
    /**
13
     * The response status code.
14
     *
15
     * @var int
16
     */
17
    private $statusCode;
18
19 7
    public function __construct(RequestInterface $request, int $statusCode, $data)
20
    {
21 7
        parent::__construct($request, $data);
22
23 7
        $this->statusCode = $statusCode;
24 7
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29 1
    public function isSuccessful(): bool
30
    {
31 1
        return $this->statusCode === Response::HTTP_OK;
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37 3
    public function isCancelled(): bool
38
    {
39 3
        return $this->getTransactionStatus() === self::TRANSACTION_STATUS_CANCELLED;
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 4
    public function getCode(): int
46
    {
47 4
        return $this->statusCode;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53 1
    public function getTransactionReference(): ?string
54
    {
55 1
        return $this->data['id'] ?? null;
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     *
61
     * Fallback on the postback data that was given by ICEPAY.
62
     * Do note: this is not (always) a reliable transaction status.
63
     *
64
     * @see https://documentation.icepay.com/payments/payment-process/payment-feedback/postback/
65
     */
66 3
    protected function getTransactionStatus(): ?string
67
    {
68 3
        if ($this->getCode() === 404) {
69 1
            return $this->request->getHttpRequest()->query->getAlpha('statusCode', null);
0 ignored issues
show
Bug introduced by
The method getHttpRequest() does not exist on Omnipay\Common\Message\RequestInterface. It seems like you code against a sub-type of Omnipay\Common\Message\RequestInterface such as Omnipay\IcepayPayments\Message\AbstractRequest. ( Ignorable by Annotation )

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

69
            return $this->request->/** @scrutinizer ignore-call */ getHttpRequest()->query->getAlpha('statusCode', null);
Loading history...
70
        }
71
72 2
        return $this->data['status'] ?? null;
73
    }
74
}
75