Completed
Push — master ( 6e6d73...1dcfbd )
by Cesar
14s queued 11s
created

ListOrdersMethod::setQueryParameters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Pagantis\OrdersApiClient\Method;
4
5
use Httpful\Http;
6
use Httpful\Request;
7
use Httpful\Response;
8
use Pagantis\OrdersApiClient\Model\Order;
9
10
/**
11
 * Class ListOrdersMethod
12
 *
13
 * @package Pagantis\OrdersApiClient\Method
14
 */
15
class ListOrdersMethod extends AbstractMethod
16
{
17
    /**
18
     * Get Order Endpoint
19
     */
20
    const ENDPOINT = '/orders';
21
22
    /**
23
     * @var array $queryParameters
24
     */
25
    protected $queryParameters;
26
27
    /**
28
     * @param array $queryParameters
29
     *
30
     * @return $this
31
     */
32
    public function setQueryParameters(array $queryParameters)
33
    {
34
        $this->queryParameters = $queryParameters;
35
36
        return $this;
37
    }
38
39
    /**
40
     * @return array|bool
41
     */
42
    public function getOrders()
43
    {
44
        $response = $this->getResponse();
45
        if ($response instanceof Response) {
0 ignored issues
show
introduced by
$response is always a sub-type of Httpful\Response.
Loading history...
46
            $responseBody = $response->body;
47
            $orders = array();
48
            foreach ($responseBody as $responseOrder) {
49
                $order = new Order();
50
                $order->import($responseOrder);
51
                $orders[] = $order;
52
            }
53
54
            return $orders;
55
        }
56
57
        return false;
58
    }
59
60
    /**
61
     * @return $this|AbstractMethod
62
     * @throws \Httpful\Exception\ConnectionErrorException
63
     * @throws \Pagantis\OrdersApiClient\Exception\HttpException
64
     */
65
    public function call()
66
    {
67
        $this->prepareRequest();
68
        return $this->setResponse($this->request->send());
69
    }
70
71
    /**
72
     * prepareRequest
73
     */
74
    public function prepareRequest()
75
    {
76
        if (!$this->request instanceof Request) {
0 ignored issues
show
introduced by
$this->request is always a sub-type of Httpful\Request.
Loading history...
77
            $this->request = $this->getRequest()
78
                ->method(Http::GET)
79
                ->uri(
80
                    $this->apiConfiguration->getBaseUri()
81
                    . self::ENDPOINT
82
                    . $this->addGetParameters($this->queryParameters)
83
                )
84
            ;
85
        }
86
    }
87
}
88