AcceptNotification::getAuthorised()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 2
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
        return $this->data;
18
    }
19
20
    public function sendData($data) {
21
        $sessionId = $this->httpRequest->query->get('sessionId') ?? $this->httpRequest->request->get('sessionId') ?? '';
22
23
        if (empty($sessionId)) {
24
            throw new InvalidRequestException('Session id is required');
25
        }
26
27
        $headers = [
28
            'Accept' => 'application/json',
29
            'Content-Type' => 'application/json',
30
            'Authorization' => 'Basic ' . $this->getAuthorization()
31
        ];
32
33
        try {
34
            $httpResponse = $this->httpClient->request('GET', $this->getEndpoint('sessions/' . $sessionId), $headers);
35
        }
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
        return $this->transaction;
50
    }
51
52
    public function getTransactionReference() {
53
        return $this->getTransaction()['id'] ?? '';
54
    }
55
56
    public function getTransactionStatus() {
57
        if ($this->getTransaction() && $this->getAuthorised() && $this->getResponseText() === 'APPROVED')  {
58
            return static::STATUS_COMPLETED;
59
        }
60
61
        return static::STATUS_FAILED;
62
    }
63
64
    public function getAuthorised() {
65
        return $this->getTransaction()['authorised'] ?? false;
66
    }
67
68
    public function getResponseText() {
69
        return strtoupper($this->getTransaction()['responseText']) ?? '';
70
    }
71
72
    public function getMessage() {
73
        return $this->getResponseText() ?? '';
74
    }
75
}