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

ConfirmOrderMethod::prepareRequest()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

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