Product   A
last analyzed

Complexity

Total Complexity 17

Size/Duplication

Total Lines 300
Duplicated Lines 17.33 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 52
loc 300
c 0
b 0
f 0
wmc 17
lcom 1
cbo 1
rs 10

17 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getProductByProductId() 0 5 1
A getProductBySellerCode() 0 5 1
A saveProduct() 0 5 1
A searchProducts() 0 16 1
A deleteProductById() 0 5 1
A deleteProductBySellerCode() 0 5 1
A updateDiscountValueByProductId() 11 11 1
A updateDiscountValueByProductSellerCode() 11 11 1
A updateProductPriceById() 15 15 1
A updateProductPriceBySellerCode() 15 15 1
A updateProductBasic() 0 23 1
A getProductQuestionList() 0 12 1
A getProductQuestionDetail() 0 4 1
A saveProductAnswer() 0 5 1
A productAllStatusCountsRequest() 0 3 1
A getProductList() 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 Onurkacmaz\LaravelN11\Models;
4
5
use Onurkacmaz\LaravelN11\Exceptions\N11Exception;
6
use Onurkacmaz\LaravelN11\Interfaces\ProductInterface;
7
use Onurkacmaz\LaravelN11\Service;
8
use SoapClient;
9
10
class Product extends Service implements ProductInterface
11
{
12
    /**
13
     * @var SoapClient|null
14
     */
15
    private $_client;
16
17
    /**
18
     * City constructor
19
     * @throws N11Exception|\SoapFault
20
     */
21
    public function __construct()
22
    {
23
        parent::__construct();
24
        $this->_client = $this->setEndPoint(self::END_POINT);
25
    }
26
27
    /**
28
     * @param int $productId
29
     * @return object
30
     * @description N11 ürün ID sini kullanarak sistemde kayıtlı olan ürünün bilgilerini getirir.
31
     */
32
    public function getProductByProductId(int $productId): object
33
    {
34
        $this->_parameters["productId"] = $productId;
35
        return $this->_client->GetProductByProductId($this->_parameters);
36
    }
37
38
    /**
39
     * @param string $productSellerCode
40
     * @return object
41
     * @description Mağaza ürün kodunu kullanarak sistemde kayıtlı olan ürünün bilgilerini getirir.
42
     */
43
    public function getProductBySellerCode(string $productSellerCode): object
44
    {
45
        $this->_parameters["sellerCode"] = $productSellerCode;
46
        return $this->_client->GetProductBySellerCode($this->_parameters);
47
    }
48
49
    /**
50
     * @param int $currentPage
51
     * @param int $pageSize
52
     * @return object
53
     */
54
    public function getProductList(int $currentPage = 1, int $pageSize = self::GENERAL_LIMIT): object
55
    {
56
        $this->_parameters["pagingData"] = [
57
            "currentPage" => $currentPage,
58
            "pageSize" => $pageSize
59
        ];
60
        return $this->_client->GetProductList($this->_parameters);
61
    }
62
63
    /**
64
     * @param array $data
65
     * @return object
66
     * @description Yeni ürün oluşturmak veya mevcut ürünü güncellemek için kullanılır.
67
     * Ürün kodu “productSellerCode” adıyla veirlen data bu mağaza için bir kayıtlı bir ürünü gösteriyorsa bu ürün güncellenir, aksi halde yeni bir ürün oluşturulur.
68
     */
69
    public function saveProduct(array $data): object
70
    {
71
        $this->_parameters["product"] = $data;
72
        return $this->_client->SaveProduct($this->_parameters);
73
    }
74
75
    /**
76
     * @param int $currentPage
77
     * @param int $pageSize
78
     * @param string|null $keyword
79
     * @param null $saleStartDate
80
     * @param null $saleEndDate
81
     * @param string $approvalStatus
82
     * @return object
83
     * @description Mağaza ürünlerini aramak için kullanılır.
84
     */
85
    public function searchProducts(int $currentPage = 1, int $pageSize = self::GENERAL_LIMIT, string $keyword = null, $saleStartDate = null, $saleEndDate = null, $approvalStatus = self::ACTIVE): object
86
    {
87
        $this->_parameters["pagingData"] = [
88
            "currentPage" => $currentPage,
89
            "pageSize" => $pageSize
90
        ];
91
        $this->_parameters["productSearch"] = [
92
            "name" => $keyword,
93
            "saleDate" => [
94
                "startDate" => $saleStartDate,
95
                "endDate" => $saleEndDate,
96
            ]
97
        ];
98
        $this->_parameters["approvalStatus"] = $approvalStatus;
99
        return $this->_client->SearchProducts($this->_parameters);
100
    }
101
102
    /**
103
     * @param int $productId
104
     * @return object
105
     * @description Kayıtlı olan bir ürünü N11 Id si kullanarak silmek için kullanılır.
106
     */
107
    public function deleteProductById(int $productId): object
108
    {
109
        $this->_parameters["productId"] = $productId;
110
        $this->_client->DeleteProductById($this->_parameters);
111
    }
112
113
    /**
114
     * @param string $productSellerCode
115
     * @return object
116
     * @description Kayıtlı olan bir ürünü mağaza ürün kodu kullanılarak silmek için kullanılır.
117
     */
118
    public function deleteProductBySellerCode(string $productSellerCode): object
119
    {
120
        $this->_parameters["productSellerCode"] = $productSellerCode;
121
        $this->_client->DeleteProductBySellerCode($this->_parameters);
122
    }
123
124
    /**
125
     * @param int $productId
126
     * @param int $discountType
127
     * @param float|int $discountValue
128
     * @param string|null $startDate
129
     * @param string|null $endDate
130
     * @return object
131
     * @description Bir ürünün N11 ürün ID sini kullanarak indirim bilgilerinin güncellenmesi için kullanılır.
132
     * Girilen indirim miktarı ürün listeleme fiyatına uygulanır.
133
     * Liste fiyatı ile ürünün indirimli fiyatı arasındaki fark kadar ürün stok birim fiyatlarına da indirim uygulanır.
134
     */
135 View Code Duplication
    public function updateDiscountValueByProductId(int $productId, int $discountType = self::DISCOUNT_AMOUNT, float $discountValue = 0, string $startDate = null, string $endDate = null): object
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...
136
    {
137
        $this->_parameters["productId"] = $productId;
138
        $this->_parameters["discountType"] = $discountType;
139
        $this->_parameters["productDiscount"] = [
140
            "discountValue" => $discountValue,
141
            "discountStartDate" => $startDate,
142
            "discountEndDate" => $endDate,
143
        ];
144
        return $this->_client->UpdateDiscountValueByProductId($this->_parameters);
145
    }
146
147
    /**
148
     * @param string $productSellerCode
149
     * @param int $discountType
150
     * @param float|int $discountValue
151
     * @param string|null $startDate
152
     * @param string|null $endDate
153
     * @return object
154
     * @description Bir ürünün mağaza ürün kodunu kullanarak indirim bilgilerinin güncellenmesi için kullanılır.
155
     * Girilen indirim miktarı ürün listeleme fiyatına uygulanır.
156
     * Liste fiyatı ile ürünün indirimli fiyatı arasındaki fark kadar ürün stok birim fiyatlarına da indirim uygulanır.
157
     */
158 View Code Duplication
    public function updateDiscountValueByProductSellerCode(string $productSellerCode, int $discountType = self::DISCOUNT_AMOUNT, float $discountValue = 0, string $startDate = null, string $endDate = null): object
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...
159
    {
160
        $this->_parameters["productSellerCode"] = $productSellerCode;
161
        $this->_parameters["discountType"] = $discountType;
162
        $this->_parameters["productDiscount"] = [
163
            "discountValue" => $discountValue,
164
            "discountStartDate" => $startDate,
165
            "discountEndDate" => $endDate,
166
        ];
167
        return $this->_client->UpdateDiscountValueByProductSellerCode($this->_parameters);
168
    }
169
170
    /**
171
     * @param int $productId
172
     * @param float $price
173
     * @param int $currencyType
174
     * @param string|null $sellerStockCode
175
     * @param float|null $optionPrice
176
     * @return object
177
     * @description Bir ürünün N11 ürün ID si kullanılarak ürünün sadece baz fiyat bilgilerini,
178
     * ürün stok birimi fiyat bilgilerini veya her ikisinin güncellenmesi için kullanılır.
179
     */
180 View Code Duplication
    public function updateProductPriceById(int $productId, float $price, $currencyType = self::TL, string $sellerStockCode = null, float $optionPrice = null): object
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...
181
    {
182
        $this->_parameters["productId"] = $productId;
183
        $this->_parameters["price"] = $price;
184
        $this->_parameters["currencyType"] = $currencyType;
185
        $this->_parameters["product"] = [
186
            "stockItems" => [
187
                "stockItem" => [
188
                    "sellerStockCode" => $sellerStockCode,
189
                    "optionPrice" => $optionPrice,
190
                ]
191
            ]
192
        ];
193
        return $this->_client->UpdateProductPriceById($this->_parameters);
194
    }
195
196
    /**
197
     * @param string $productSellerCode
198
     * @param float $price
199
     * @param int $currencyType
200
     * @param string|null $sellerStockCode
201
     * @param float|null $optionPrice
202
     * @return object
203
     * @description Bir ürünün N11 ürün ID si kullanılarak ürünün sadece baz fiyat bilgilerini,
204
     * ürün stok birimi fiyat bilgilerini veya her ikisinin güncellenmesi için kullanılır.
205
     */
206 View Code Duplication
    public function updateProductPriceBySellerCode(string $productSellerCode, float $price, $currencyType = self::TL, string $sellerStockCode = null, float $optionPrice = null): object
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...
207
    {
208
        $this->_parameters["productSellerCode"] = $productSellerCode;
209
        $this->_parameters["price"] = $price;
210
        $this->_parameters["currencyType"] = $currencyType;
211
        $this->_parameters["product"] = [
212
            "stockItems" => [
213
                "stockItem" => [
214
                    "sellerStockCode" => $sellerStockCode,
215
                    "optionPrice" => $optionPrice,
216
                ]
217
            ]
218
        ];
219
        return $this->_client->UpdateProductPriceBySellerCode($this->_parameters);
220
    }
221
222
    /**
223
     * @param array $data
224
     * @return object
225
     * @description Kayıtlı olan bir ürünün, N11 ürün ID’si ya da mağaza kodu ile ürün fiyatını, ürün üzerindeki indirimi ve isteğe bağlı olarak stok ID’si ya da mağaza stok kodu ile belirtilen stoklarının, miktarı ve ilgili stok biriminin liste fiyatının güncellenmesi için kullanılır.
226
     */
227
    public function updateProductBasic(array $data): object
228
    {
229
        $this->_parameters["productId"] = $data["productId"];
230
        $this->_parameters["productSellerCode"] = $data["productSellerCode"];
231
        $this->_parameters["price"] = $data["price"];
232
        $this->_parameters["description"] = $data["description"];
233
        $this->_parameters["images"] = [
234
            "image" => $data["images"]
235
        ];
236
        $this->_parameters["productDiscount"] = [
237
            "discountType" => $data["discountType"],
238
            "discountValue" => $data["discountValue"],
239
            "discountStartDate" => $data["startDate"],
240
            "discountEndDate" => $data["discountEndDate"],
241
            "discountStockCode" => $data["discountStockCode"],
242
            "optionPrice" => $data["optionPrice"],
243
            "quantity" => $data["quantity"],
244
        ];
245
        $this->_parameters["stockItems"] = [
246
            "stockItem" => $data["stockItems"]
247
        ];
248
        return $this->_client->UpdateProductBasic($this->_parameters);
249
    }
250
251
    /**
252
     * @param int $productId
253
     * @param string $buyerEmail
254
     * @param string $subject
255
     * @param $status
256
     * @param string $questionDate
257
     * @param int $currentPage
258
     * @param int $pageSize
259
     * @return object
260
     * @description Müşterileriniz tarafından mağazanıza sorulan soruları listeler.
261
     * Sorularınızı listelemek için Appkey ve Appsecret bilgileriniz gerekmektedir.
262
     */
263
    public function getProductQuestionList(int $productId, string $buyerEmail, string $subject, $status, string $questionDate, int $currentPage = 1, int $pageSize = self::GENERAL_LIMIT): object {
264
        $this->_parameters["currentPage"] = $currentPage;
265
        $this->_parameters["pageSize"] = $pageSize;
266
        $this->_parameters["productQuestionSearch"] = [
267
            "productId" => $productId,
268
            "buyerEmail" => $buyerEmail,
269
            "subject" => $subject,
270
            "status" => $status,
271
            "questionDate" => $questionDate,
272
        ];
273
        return $this->_client->GetProductQuestionList($this->_parameters);
274
    }
275
276
    /**
277
     * @param int $productQuestionId
278
     * @return object
279
     * @description GetProductQuestionList ile sıralanan soruların içeriğini, buradan gelen ID ve getProductQuestionDetail yardımıyla görüntüleyebilirsiniz.
280
     */
281
    public function getProductQuestionDetail(int $productQuestionId): object {
282
        $this->_parameters["productQuestionId"] = $productQuestionId;
283
        return $this->_client->GetProductQuestionDetail($this->_parameters);
284
    }
285
286
    /**
287
     * @param int $productQuestionId
288
     * @param string $productAnswer
289
     * @return object
290
     * @description Müşterilerden gelen ürün sorularını cevaplamak için kullanılır.
291
     * Cevap vermek için productQuestionId değeri zorunludur ve GetProductQuestionList‘ten id edinilebilir.
292
     */
293
    public function saveProductAnswer(int $productQuestionId, string $productAnswer): object {
294
        $this->_parameters["productQuestionId"] = $productQuestionId;
295
        $this->_parameters["productAnswer"] = $productAnswer;
296
        return $this->_client->SaveProductAnswer($this->_parameters);
297
    }
298
299
    /**
300
     * @return object
301
     * @description Seller ın sahip olduğu tüm ürünleri, ait olduğu statülere göre sınıflandırıp, statü/sayı bilgisi döner.
302
     * Seller a göre cevap döndüğü için istekte sadece authorization olması yeterlidir.
303
     * Her bir seller maksimum 3 kez istek gönderebilir.
304
     */
305
    public function productAllStatusCountsRequest(): object {
306
        return $this->_client->ProductAllStatusCountsRequest($this->_parameters);
307
    }
308
309
}
310