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

GetOrderMethod::setOrderId()   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\Exception\ClientException;
9
use Pagantis\OrdersApiClient\Model\Order;
10
11
/**
12
 * Class GetOrderMethod
13
 *
14
 * @package Pagantis\OrdersApiClient\Method
15
 */
16
class GetOrderMethod extends AbstractMethod
17
{
18
    /**
19
     * Get Order Endpoint
20
     */
21
    const ENDPOINT = '/orders';
22
23
    /**
24
     * @var string $orderId
25
     */
26
    protected $orderId;
27
28
    /**
29
     * @param string $orderId
30
     *
31
     * @return GetOrderMethod
32
     */
33
    public function setOrderId($orderId)
34
    {
35
        $this->orderId = $orderId;
36
37
        return $this;
38
    }
39
40
    /**
41
     * @return $this|AbstractMethod
42
     * @throws \Httpful\Exception\ConnectionErrorException
43
     * @throws \Pagantis\OrdersApiClient\Exception\HttpException
44
     * @throws ClientException
45
     */
46
    public function call()
47
    {
48
        if (is_string($this->orderId)) {
0 ignored issues
show
introduced by
The condition is_string($this->orderId) is always true.
Loading history...
49
            $this->prepareRequest();
50
            return $this->setResponse($this->request->send());
51
        }
52
        throw new ClientException('Please set OrderId');
53
    }
54
55
    /**
56
     * @return bool|Order
57
     */
58
    public function getOrder()
59
    {
60
        $response = $this->getResponse();
61
        if ($response instanceof Response) {
0 ignored issues
show
introduced by
$response is always a sub-type of Httpful\Response.
Loading history...
62
            $order = new Order();
63
            $order->import($this->getResponse()->body);
64
            return $order;
65
        }
66
67
        return false;
68
    }
69
70
    /**
71
     * prepareRequest
72
     */
73
    protected function prepareRequest()
74
    {
75
        if (!$this->request instanceof Request) {
0 ignored issues
show
introduced by
$this->request is always a sub-type of Httpful\Request.
Loading history...
76
            $this->request = $this->getRequest()
77
                ->method(Http::GET)
78
                ->uri(
79
                    $this->apiConfiguration->getBaseUri()
80
                    . self::ENDPOINT
81
                    . self::SLASH
82
                    . $this->orderId
83
                )
84
            ;
85
        }
86
    }
87
}
88