Completed
Push — master ( 08a67d...83c463 )
by Christian
13s queued 10s
created

MWSMerchantFulfillment   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 82
Duplicated Lines 34.15 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 28
loc 82
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getEligibleShippingServices() 0 8 1
A parseResponse() 0 12 1
A createShipment() 0 8 1
A cancelShipment() 10 10 1
A getShipment() 10 10 1
A getServiceStatus() 8 8 1
A getAdditionalSellerInputs() 0 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Looxis\LaravelAmazonMWS;
4
5
class MWSMerchantFulfillment
6
{
7
    const VERSION = '2015-06-01';
8
9
    protected $client;
10
11
    public function __construct(MWSClient $client)
12
    {
13
        $this->client = $client;
14
    }
15
16
    public function getEligibleShippingServices($params = [])
17
    {
18
        $action = 'GetEligibleShippingServices';
19
20
        $response = $this->client->post($action, '/MerchantFulfillment/'.self::VERSION, self::VERSION, $params);
21
22
        return $this->parseResponse($response, $action.'Result');
23
    }
24
25
    public function parseResponse($response, $resultTypeName)
26
    {
27
        $requestId = data_get($response, 'ResponseMetadata.RequestId');
28
        $data = data_get($response, $resultTypeName);
29
30
        $data = [
31
            'request_id' => $requestId,
32
            'data' => $data,
33
        ];
34
35
        return $data;
36
    }
37
38
    public function createShipment($params = [])
39
    {
40
        $action = 'CreateShipment';
41
42
        $response = $this->client->post($action, '/MerchantFulfillment/'.self::VERSION, self::VERSION, $params);
43
44
        return $this->parseResponse($response, $action.'Result');
45
    }
46
47 View Code Duplication
    public function cancelShipment($shipmentId)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
48
    {
49
        $action = 'CancelShipment';
50
51
        $response = $this->client->post($action, '/MerchantFulfillment/'.self::VERSION, self::VERSION, [
52
            'ShipmentId' => $shipmentId,
53
        ]);
54
55
        return $this->parseResponse($response, $action.'Result');
56
    }
57
58 View Code Duplication
    public function getShipment($shipmentId)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
59
    {
60
        $action = 'GetShipment';
61
62
        $response = $this->client->post($action, '/MerchantFulfillment/'.self::VERSION, self::VERSION, [
63
            'ShipmentId' => $shipmentId,
64
        ]);
65
66
        return $this->parseResponse($response, $action.'Result');
67
    }
68
69 View Code Duplication
    public function getServiceStatus()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
70
    {
71
        $action = 'GetServiceStatus';
72
73
        $response = $this->client->post($action, '/MerchantFulfillment/'.self::VERSION, self::VERSION);
74
75
        return $this->parseResponse($response, $action.'Result');
76
    }
77
78
    public function getAdditionalSellerInputs($params)
79
    {
80
        $action = 'GetAdditionalSellerInputs';
81
82
        $response = $this->client->post($action, '/MerchantFulfillment/'.self::VERSION, self::VERSION, $params);
83
84
        return $this->parseResponse($response, $action.'Result');
85
    }
86
}
87