Completed
Push — master ( 1c1fd6...5cf71c )
by Christian
06:00
created

MWSOrders::list()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Looxis\LaravelAmazonMWS;
4
5
class MWSOrders
6
{
7
    const VERSION = '2013-09-01';
8
9
    protected $client;
10
11
    public function __construct(MWSClient $client)
12
    {
13
        $this->client = $client;
14
    }
15
16
    public function list($params = [])
0 ignored issues
show
Unused Code introduced by
The parameter $params is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
17
    {
18
        //TODO
19
    }
20
21
    public function get($ids)
22
    {
23
        $ids = is_array($ids) ? $ids : func_get_args();
24
        $params = [];
25
26
        foreach ($ids as $key => $id) {
27
            $keyName = 'AmazonOrderId.Id.'.($key + 1);
28
            $params[$keyName] = $id;
29
        }
30
31
        $response = $this->client->post('GetOrder', '/Orders/'.self::VERSION, self::VERSION, $params);
32
33
        return $this->parseResponse($response, 'GetOrderResult', 'Orders.Order');
34
    }
35
36
    public function getItems($id)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
37
    {
38
        $response = $this->client->post('ListOrderItems', '/Orders/' . self::VERSION, self::VERSION);
39
40
        return $this->parseResponse($response, 'ListOrderItemsResult', 'OrderItems.OrderItem');
41
    }
42
43
    protected function parseResponse($response, $resultTypeName, $dataName)
44
    {
45
        $requestId = data_get($response, 'ResponseMetadata.RequestId');
46
        $orders = data_get($response, $resultTypeName. '.' . $dataName);
47
        $nextToken = data_get($response, $resultTypeName. '.NextToken');
48
        
49
        $data = [
50
            'request_id' => $requestId,
51
            'data' => $orders,
52
        ];
53
54
        if ($nextToken) {
55
            $data['next_token'] = $nextToken;
56
        }
57
58
        if ($resultTypeName == 'ListOrderItemsResult') {
59
            $data['order_id'] = data_get($response, $resultTypeName . '.AmazonOrderId');
60
        }
61
62
        return $data;
63
    }
64
}
65