MWSFeeds   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 1
dl 0
loc 98
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getContent() 0 4 1
A setParams() 0 6 1
A getParams() 0 4 1
A setContent() 0 6 1
A getType() 0 4 1
A setType() 0 6 1
A submit() 0 12 1
A parseSubmitFeedResponse() 0 10 1
A getFeedSubmissionResult() 0 10 1
A parseSubmissionResultResponse() 0 12 2
1
<?php
2
3
namespace Looxis\LaravelAmazonMWS;
4
5
class MWSFeeds
6
{
7
    const VERSION = '2009-01-01';
8
9
    protected $client;
10
    protected $content;
11
    protected $type;
12
    protected $params = [];
13
14
    public function __construct(MWSClient $client)
15
    {
16
        $this->client = $client;
17
    }
18
19
    public function getContent()
20
    {
21
        return $this->content;
22
    }
23
24
    public function setParams($params)
25
    {
26
        $this->params = $params;
27
28
        return $this;
29
    }
30
31
    public function getParams()
32
    {
33
        return $this->params;
34
    }
35
36
    public function setContent($content)
37
    {
38
        $this->content = $content;
39
40
        return $this;
41
    }
42
43
    public function getType()
44
    {
45
        return $this->type;
46
    }
47
48
    public function setType($type)
49
    {
50
        $this->type = $type;
51
52
        return $this;
53
    }
54
55
    public function submit($purgeAndReplace = false, $amazonOrderId = null, $documentType = null)
0 ignored issues
show
Unused Code introduced by
The parameter $documentType 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...
Unused Code introduced by
The parameter $amazonOrderId 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...
56
    {
57
        $contentmd5Hash = base64_encode(md5($this->getContent(), true));
58
        $params = array_merge([
59
            'FeedType' => $this->type,
60
            'PurgeAndReplace' => $purgeAndReplace,
61
            'ContentMD5Value' => $contentmd5Hash,
62
        ], $this->getParams());
63
        $response = $this->client->post('SubmitFeed', '/', self::VERSION, $params, $this->getContent());
64
65
        return $this->parseSubmitFeedResponse($response);
66
    }
67
68
    protected function parseSubmitFeedResponse($response)
69
    {
70
        $requestId = data_get($response, 'ResponseMetadata.RequestId');
71
        $feed = data_get($response, 'SubmitFeedResult.FeedSubmissionInfo');
72
73
        return [
74
            'request_id' => $requestId,
75
            'data' => $feed,
76
        ];
77
    }
78
79
    public function getFeedSubmissionResult($amazonFeedSubmissionId)
80
    {
81
        $params = [
82
            'FeedSubmissionId' => $amazonFeedSubmissionId,
83
        ];
84
85
        $response = $this->client->post('GetFeedSubmissionResult', '/', self::VERSION, $params);
86
87
        return $this->parseSubmissionResultResponse($response);
88
    }
89
90
    protected function parseSubmissionResultResponse($response)
91
    {
92
        if (is_null(data_get($response, 'Message.ProcessingReport.StatusCode'))) {
93
            return (string) $response;
94
        }
95
96
        return [
97
            'status_code' => data_get($response, 'Message.ProcessingReport.StatusCode'),
98
            'processing_summary' => data_get($response, 'Message.ProcessingReport.ProcessingSummary'),
99
            'result' => data_get($response, 'Message.ProcessingReport.Result'),
100
        ];
101
    }
102
}
103