Passed
Push — main ( b1b5d7...536cb4 )
by
unknown
03:11
created

AcceptNotification::getAuthorised()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Omnipay\WindcaveHpp\Message;
4
5
use Omnipay\Common\Exception\InvalidRequestException;
6
use Omnipay\Common\Http\ClientInterface;
7
use Omnipay\Common\Message\AbstractRequest;
8
use Omnipay\Common\Message\NotificationInterface;
9
use Symfony\Component\HttpFoundation\Request as HttpRequest;
10
11
class AcceptNotification extends PurchaseRequest implements NotificationInterface{
12
    protected $data;
13
14
    protected $transaction;
15
16
    public function getData()
17
    {
18
        return $this->data;
19
    }
20
    public function sendData($data)
21
    {
22
        $sessionId = $this->httpRequest->query->get('sessionId') ?? $this->httpRequest->request->get('sessionId') ?? '';
23
24
        if ( empty($sessionId) ) {
25
            throw new InvalidRequestException('Session id is required');
26
        }
27
28
        $headers = [
29
            'Accept' => 'application/json',
30
            'Content-Type' => 'application/json',
31
            'Authorization' => 'Basic ' . $this->getAuthorization()
32
        ];
33
34
        try {
35
            $httpResponse = $this->httpClient->request('GET', $this->getEndpoint('sessions/' . $sessionId), $headers);
36
        } catch (\Exception $exception) {
37
            throw new InvalidRequestException($exception->getMessage());
38
        }
39
40
        $transactionData = json_decode($httpResponse->getBody()->getContents(), true);
41
42
        $this->data = $transactionData;
43
        $this->transaction = $transactionData['transactions'][0] ?? [];
44
45
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Omnipay\WindcaveHpp\Message\AcceptNotification which is incompatible with the return type mandated by Omnipay\Common\Message\R...stInterface::sendData() of Omnipay\Common\Message\ResponseInterface.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
46
    }
47
48
    public function getTransaction()
49
    {
50
        return $this->transaction;
51
    }
52
53
    public function getTransactionReference()
54
    {
55
        return $this->getTransaction()['id'] ?? '';
56
    }
57
58
    public function getTransactionStatus()
59
    {
60
        if ( $this->getTransaction() && $this->getAuthorised() && $this->getResponseText() === 'APPROVED' )  {
61
            return static::STATUS_COMPLETED;
62
        }
63
64
        return static::STATUS_FAILED;
65
    }
66
67
    public function getAuthorised()
68
    {
69
        return $this->getTransaction()['authorised'] ?? false;
70
    }
71
72
    public function getResponseText()
73
    {
74
        return strtoupper($this->getTransaction()['responseText']) ?? '';
75
    }
76
77
    public function getMessage()
78
    {
79
        return $this->getResponseText() ?? '';
80
    }
81
}