Code Duplication    Length = 41-42 lines in 2 locations

src/Api/Cart.php 2 locations

@@ 60-101 (lines=42) @@
57
     *
58
     * @return Cart|ResponseInterface
59
     */
60
    public function create(string $customer, string $channel, string $localeCode)
61
    {
62
        if (empty($customer)) {
63
            throw new InvalidArgumentException('Customers field cannot be empty');
64
        }
65
66
        if (empty($channel)) {
67
            throw new InvalidArgumentException('Channel cannot be empty');
68
        }
69
70
        if (empty($localeCode)) {
71
            throw new InvalidArgumentException('Locale code cannot be empty');
72
        }
73
74
        $params = [
75
            'customer' => $customer,
76
            'channel' => $channel,
77
            'localeCode' => $localeCode,
78
        ];
79
80
        $response = $this->httpPost('/api/v1/carts/', $params);
81
82
        if (!$this->hydrator) {
83
            return $response;
84
        }
85
86
        // Use any valid status code here
87
        if (201 !== $response->getStatusCode()) {
88
            switch ($response->getStatusCode()) {
89
                case 400:
90
                    throw new DomainExceptions\ValidationException();
91
                    break;
92
                default:
93
                    $this->handleErrors($response);
94
95
                    break;
96
            }
97
        }
98
99
        return $this->hydrator->hydrate($response, Model::class);
100
    }
101
102
    /**
103
     * @param int    $cartId
104
     * @param string $variant
@@ 112-152 (lines=41) @@
109
     *
110
     * @return CartItem|ResponseInterface
111
     */
112
    public function addItem(int $cartId, string $variant, int $quantity)
113
    {
114
        if (empty($cartId)) {
115
            throw new InvalidArgumentException('Cart id field cannot be empty');
116
        }
117
118
        if (empty($variant)) {
119
            throw new InvalidArgumentException('variant cannot be empty');
120
        }
121
122
        if (empty($quantity)) {
123
            throw new InvalidArgumentException('quantity cannot be empty');
124
        }
125
126
        $params = [
127
            'variant' => $variant,
128
            'quantity' => $quantity,
129
        ];
130
131
        $response = $this->httpPost("/api/v1/carts/{$cartId}/items/", $params);
132
133
        if (!$this->hydrator) {
134
            return $response;
135
        }
136
137
        // Use any valid status code here
138
        if (201 !== $response->getStatusCode()) {
139
            switch ($response->getStatusCode()) {
140
                case 400:
141
                    throw new DomainExceptions\ValidationException();
142
                    break;
143
                default:
144
                    $this->handleErrors($response);
145
146
                    break;
147
            }
148
        }
149
150
        return $this->hydrator->hydrate($response, CartItem::class);
151
    }
152
}
153