ProductStock   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 187
Duplicated Lines 42.25 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 79
loc 187
c 0
b 0
f 0
wmc 9
lcom 1
cbo 1
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getProductStockByProductId() 0 5 1
A getProductStockBySellerCode() 0 5 1
A updateStockByStockAttributes() 19 19 1
A updateStockByStockId() 11 11 1
A updateStockByStockSellerCode() 11 11 1
A increaseStockByStockAttributes() 18 18 1
A increaseStockByStockId() 10 10 1
A increaseStockByStockSellerCode() 10 10 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\ProductStockInterface;
7
use Onurkacmaz\LaravelN11\Service;
8
use SoapClient;
9
10
class ProductStock extends Service implements ProductStockInterface
11
{
12
13
    /**
14
     * @var SoapClient|null
15
     */
16
    private $_client;
17
18
    /**
19
     * Category constructor
20
     * endPoint set edildi.
21
     * @throws N11Exception|\SoapFault
22
     */
23
    public function __construct()
24
    {
25
        parent::__construct();
26
        $this->_client = $this->setEndPoint(self::END_POINT);
27
    }
28
29
    /**
30
     * @param int $productId
31
     * @return mixed
32
     * @description Sistemde kayıtlı olan ürünün N11 ürün ID si ile ürün stok bilgilerini getiren metottur.
33
     * Cevap içinde stok durumunun “version” bilgisi de vardır, ürün stoklarında değişme olduysa bu versiyon bilgisi artacaktır,
34
     * Çağrı yapan taraf versiyon bilgisini kontrol ederek N11 e verilen stok bilgilerinde değişim olup olmadığını anlayabilir.
35
     */
36
    public function getProductStockByProductId(int $productId): object
37
    {
38
        $this->_parameters["product"]["id"] = $productId;
39
        return $this->_client->GetProductStockByProductId($this->_parameters);
40
    }
41
42
    /**
43
     * @param string $productSellerCode
44
     * @return mixed
45
     * @description Sistemde kayıtlı olan ürünün N11 ürün ID si ile ürün stok bilgilerini getiren metottur.
46
     * Cevap içinde stok durumunun “version” bilgisi de vardır, ürün stoklarında değişme olduysa bu versiyon bilgisi artacaktır,
47
     * Çağrı yapan taraf versiyon bilgisini kontrol ederek N11 e verilen stok bilgilerinde değişim olup olmadığını anlayabilir.
48
     */
49
    public function getProductStockBySellerCode(string $productSellerCode): object
50
    {
51
        $this->_parameters["productSellerCode"] = $productSellerCode;
52
        return $this->_client->GetProductStockBySellerCode($this->_parameters);
53
    }
54
55
    /**
56
     * @param int $productId
57
     * @param string $attrName
58
     * @param string $attrValue
59
     * @param int $quantity
60
     * @param int $version
61
     * @return mixed
62
     * @description Ürün stok seçenek bilgilerini kullanarak kayıtlı ürünün stok bilgilerini güncellemek için kullanılır.
63
     * Ürün n11 ID si ve stok seçenek bilgileri girilerek güncelleme işlemi yapılır.
64
     * Bir ürüne ait stok bilgilerine, ProductStockService içindeki GetProductStockByProductId veya GetProductStockBySellerCode metotları ile ulaşılabilir.
65
     * Bir ürün için tüm stok bilgilerini güncelleme işlemi gerçekleştirilebilir.
66
     * N11 tarafında değişen stok miktarlarını ezmemek için, “version” bilgisi verilmesi durumunda ilgili ürün stok bilgisinin N11 de versiyonu ile karşılaştırma yapılır, stok versiyon numaraları uyumsuz ise işlem gerçekleştirilmez.
67
     */
68 View Code Duplication
    public function updateStockByStockAttributes(int $productId, string $attrName, string $attrValue, int $quantity, int $version = 0): 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...
69
    {
70
        $this->_parameters["product"] = [
71
            "Id" => $productId,
72
            "stockItems" => [
73
                "stockItem" => [
74
                    "attributes" => [
75
                        "attribute" => [
76
                            "name" => $attrName,
77
                            "value" => $attrValue,
78
                            "quantity" => $quantity,
79
                            "version" => $version,
80
                        ]
81
                    ]
82
                ]
83
            ]
84
        ];
85
        return $this->_client->DeleteAndUpdateStockByStockAttributes($this->_parameters);
86
    }
87
88
    /**
89
     * @param int $stockItemId
90
     * @param int $quantity
91
     * @param int $version
92
     * @return mixed
93
     * @description n11 ürün stok ID si kullanarak kayıtlı ürünün stok bilgilerini güncellemek için kullanılır.
94
     * n11 ürün stok ID si ve miktar bilgileri girilerek güncelleme işlemi yapılır.
95
     * Bir ürüne ait n11 ürün stok ID sine, ProductStockService içindeki GetProductStockByProductId veya GetProductStockBySellerCode metotları ile ulaşılabilir.
96
     * N11 tarafında değişen stok miktarlarını ezmemek için, “version” bilgisi verilmesi durumunda ilgili ürün stok bilgisinin N11 de versiyonu ile karşılaştırma yapılır, stok versiyon numaraları uyumsuz ise işlem gerçekleştirilmez.
97
     */
98 View Code Duplication
    public function updateStockByStockId(int $stockItemId, int $quantity, int $version = 0): 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...
99
    {
100
        $this->_parameters["stockItems"] = [
101
            "stockItem" => [
102
                "id" => $stockItemId,
103
                "quantity" => $quantity,
104
                "version" => $version,
105
            ]
106
        ];
107
        return $this->_client->UpdateStockByStockId($this->_parameters);
108
    }
109
110
    /**
111
     * @param string $stockSellerCode
112
     * @param int $quantity
113
     * @param int $version
114
     * @return mixed
115
     * @description Mağaza ürün stok kodu kullanarak kayıtlı ürünün stok bilgilerini güncellemek için kullanılır.
116
     * Mağaza ürün stok kodu ve miktar bilgileri girilerek güncelleme işlemi yapılır.
117
     * N11 tarafında değişen stok miktarlarını ezmemek için, “version” bilgisi verilmesi durumunda ilgili ürün stok bilgisinin N11 de versiyonu ile karşılaştırma yapılır, stok versiyon numaraları uyumsuz ise işlem gerçekleştirilmez.
118
     */
119 View Code Duplication
    public function updateStockByStockSellerCode(string $stockSellerCode, int $quantity, int $version = 0): 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...
120
    {
121
        $this->_parameters["stockItems"] = [
122
            "stockItem" => [
123
                "sellerStockCode" => $stockSellerCode,
124
                "quantity" => $quantity,
125
                "version" => $version,
126
            ]
127
        ];
128
        return $this->_client->UpdateStockByStockSellerCode($this->_parameters);
129
    }
130
131
    /**
132
     * @param string $attrName
133
     * @param string $attrValue
134
     * @param int $quantityToIncrease
135
     * @param int $version
136
     * @return mixed
137
     * @description Bir ürünün stok seçenek bilgilerini kullanarak stok miktarını arttırmak için kullanılır.
138
     * N11 tarafında değişen stok miktarlarını ezmemek için, “version” bilgisi verilmesi durumunda ilgili ürün stok bilgisinin N11 de versiyonu ile karşılaştırma yapılır, stok versiyon numaraları uyumsuz ise işlem gerçekleştirilmez.
139
     */
140 View Code Duplication
    public function increaseStockByStockAttributes(string $attrName, string $attrValue, int $quantityToIncrease, int $version = 0): 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...
141
    {
142
        $this->_parameters["product"] = [
143
            "stockItems" => [
144
                "stockItem" => [
145
                    "attributes" => [
146
                        "attribute" => [
147
                            "name" => $attrName,
148
                            "value" => $attrValue,
149
                        ]
150
                    ],
151
                    "quantityToIncrease" => $quantityToIncrease,
152
                    "version" => $version
153
                ]
154
            ]
155
        ];
156
        return $this->_client->IncreaseStockByStockAttributes($this->_parameters);
157
    }
158
159
    /**
160
     * @param int $stockItemId
161
     * @param int $quantityToIncrease
162
     * @return mixed
163
     * @description Bir ürünün n11 ürün stok ID bilgisini kullanarak stok miktarını arttırmak için kullanılır.
164
     * Bir ürüne ait n11 ürün stok ID sine, ProductStockService içindeki GetProductStockByProductId veya GetProductStockBySellerCode metotları ile ulaşılabilir.
165
     * N11 tarafında değişen stok miktarlarını ezmemek için, “version” bilgisi verilmesi durumunda ilgili ürün stok bilgisinin N11 de versiyonu ile karşılaştırma yapılır, stok versiyon numaraları uyumsuz ise işlem gerçekleştirilmez.
166
     */
167 View Code Duplication
    public function increaseStockByStockId(int $stockItemId, int $quantityToIncrease): 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...
168
    {
169
        $this->_parameters["stockItems"] = [
170
            "stockItem" => [
171
                "id" => $stockItemId,
172
                "quantityToIncrease" => $quantityToIncrease
173
            ]
174
        ];
175
        return $this->_client->IncreaseStockByStockId($this->_parameters);
176
    }
177
178
    /**
179
     * @param string $sellerStockCode
180
     * @param int $quantityToIncrease
181
     * @return mixed
182
     * @description Bir ürünün mağaza stok kodu kullanarak stok miktarını arttırmak için kullanılır.
183
     * N11 tarafında değişen stok miktarlarını ezmemek için, “version” bilgisi verilmesi durumunda ilgili ürün stok bilgisinin N11 de versiyonu ile karşılaştırma yapılır, stok versiyon numaraları uyumsuz ise işlem gerçekleştirilmez.
184
     */
185 View Code Duplication
    public function increaseStockByStockSellerCode(string $sellerStockCode, int $quantityToIncrease): 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...
186
    {
187
        $this->_parameters["stockItems"] = [
188
            "stockItem" => [
189
                "sellerStockCode" => $sellerStockCode,
190
                "quantityToIncrease" => $quantityToIncrease
191
            ]
192
        ];
193
        return $this->_client->IncreaseStockByStockSellerCode($this->_parameters);
194
    }
195
196
}
197