FetchEventRequest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 30
rs 10
c 1
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A sendData() 0 11 2
A getData() 0 5 1
A getEventId() 0 3 1
A setEventId() 0 3 1
1
<?php
2
3
namespace Omnipay\GoCardless\Message;
4
5
/**
6
 * Fetch the details of a specific event (webhook notification) from GoCardless
7
 *
8
 * @see https://developer.gocardless.com/api-reference/#events-get-a-single-event
9
 */
10
class FetchEventRequest extends AbstractRequest
11
{
12
    public function getEventId()
13
    {
14
        return $this->getParameter('eventId');
15
    }
16
17
    public function setEventId($value)
18
    {
19
        return $this->setParameter('eventId', $value);
20
    }
21
22
    public function getData()
23
    {
24
        $this->validate('eventId');
25
        $this->action = '/events/'.$this->getEventId();
26
        return null;
27
    }
28
29
    public function sendData($data)
30
    {
31
        $response = $this->sendRequest($data, 'GET');
32
        $json = json_decode($response->getBody()->getContents(), true);
33
        // if there's an event, retrieve the details, otherwise pass through the error
34
        $notification = isset($json['events']) ? $json['events'] : $json;
35
36
        $this->response = new WebhookEventNotification($this->httpClient, $this->httpRequest);
0 ignored issues
show
Documentation Bug introduced by
It seems like new Omnipay\GoCardless\M...nt, $this->httpRequest) of type Omnipay\GoCardless\Messa...ebhookEventNotification is incompatible with the declared type Omnipay\Common\Message\ResponseInterface of property $response.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
37
        $this->response->initialize(array_replace($this->getParameters(), ['notification' => $notification]));
38
39
        return $this->response;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->response returns the type Omnipay\GoCardless\Messa...ebhookEventNotification 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...
40
    }
41
}
42