Skip to content

Commit e527114

Browse files
refactored code
1 parent 1116437 commit e527114

File tree

1 file changed

+23
-30
lines changed

1 file changed

+23
-30
lines changed

app/code/Magento/CatalogInventory/Model/StockState.php

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\CatalogInventory\Api\StockStateInterface;
1010
use Magento\CatalogInventory\Model\Spi\StockRegistryProviderInterface;
1111
use Magento\CatalogInventory\Model\Spi\StockStateProviderInterface;
12+
use Magento\Framework\DataObject;
1213

1314
/**
1415
* Interface StockState
@@ -50,12 +51,11 @@ public function __construct(
5051
* @param int $scopeId
5152
* @return bool
5253
*/
53-
public function verifyStock($productId, $scopeId = null)
54+
public function verifyStock($productId, $scopeId = null): bool
5455
{
55-
// if ($scopeId === null) {
56-
$scopeId = $this->stockConfiguration->getDefaultScopeId();
57-
// }
56+
$scopeId = $this->stockConfiguration->getDefaultScopeId();
5857
$stockItem = $this->stockRegistryProvider->getStockItem($productId, $scopeId);
58+
5959
return $this->stockStateProvider->verifyStock($stockItem);
6060
}
6161

@@ -64,12 +64,11 @@ public function verifyStock($productId, $scopeId = null)
6464
* @param int $scopeId
6565
* @return bool
6666
*/
67-
public function verifyNotification($productId, $scopeId = null)
67+
public function verifyNotification($productId, $scopeId = null): bool
6868
{
69-
// if ($scopeId === null) {
70-
$scopeId = $this->stockConfiguration->getDefaultScopeId();
71-
// }
69+
$scopeId = $this->stockConfiguration->getDefaultScopeId();
7270
$stockItem = $this->stockRegistryProvider->getStockItem($productId, $scopeId);
71+
7372
return $this->stockStateProvider->verifyNotification($stockItem);
7473
}
7574

@@ -79,15 +78,13 @@ public function verifyNotification($productId, $scopeId = null)
7978
* @param int $productId
8079
* @param float $qty
8180
* @param int $scopeId
82-
* @exception \Magento\Framework\Exception\LocalizedException
8381
* @return bool
8482
*/
85-
public function checkQty($productId, $qty, $scopeId = null)
83+
public function checkQty($productId, $qty, $scopeId = null): bool
8684
{
87-
// if ($scopeId === null) {
88-
$scopeId = $this->stockConfiguration->getDefaultScopeId();
89-
// }
85+
$scopeId = $this->stockConfiguration->getDefaultScopeId();
9086
$stockItem = $this->stockRegistryProvider->getStockItem($productId, $scopeId);
87+
9188
return $this->stockStateProvider->checkQty($stockItem, $qty);
9289
}
9390

@@ -100,12 +97,11 @@ public function checkQty($productId, $qty, $scopeId = null)
10097
* @param int $scopeId
10198
* @return float
10299
*/
103-
public function suggestQty($productId, $qty, $scopeId = null)
100+
public function suggestQty($productId, $qty, $scopeId = null): float
104101
{
105-
// if ($scopeId === null) {
106-
$scopeId = $this->stockConfiguration->getDefaultScopeId();
107-
// }
102+
$scopeId = $this->stockConfiguration->getDefaultScopeId();
108103
$stockItem = $this->stockRegistryProvider->getStockItem($productId, $scopeId);
104+
109105
return $this->stockStateProvider->suggestQty($stockItem, $qty);
110106
}
111107

@@ -116,27 +112,25 @@ public function suggestQty($productId, $qty, $scopeId = null)
116112
* @param int $scopeId
117113
* @return float
118114
*/
119-
public function getStockQty($productId, $scopeId = null)
115+
public function getStockQty($productId, $scopeId = null): float
120116
{
121-
// if ($scopeId === null) {
122-
$scopeId = $this->stockConfiguration->getDefaultScopeId();
123-
// }
117+
$scopeId = $this->stockConfiguration->getDefaultScopeId();
124118
$stockItem = $this->stockRegistryProvider->getStockItem($productId, $scopeId);
119+
125120
return $this->stockStateProvider->getStockQty($stockItem);
126121
}
127122

128123
/**
129124
* @param int $productId
130125
* @param float $qty
131126
* @param int $websiteId
132-
* @return \Magento\Framework\DataObject
127+
* @return DataObject
133128
*/
134-
public function checkQtyIncrements($productId, $qty, $websiteId = null)
129+
public function checkQtyIncrements($productId, $qty, $websiteId = null): DataObject
135130
{
136-
// if ($websiteId === null) {
137-
$websiteId = $this->stockConfiguration->getDefaultScopeId();
138-
// }
131+
$websiteId = $this->stockConfiguration->getDefaultScopeId();
139132
$stockItem = $this->stockRegistryProvider->getStockItem($productId, $websiteId);
133+
140134
return $this->stockStateProvider->checkQtyIncrements($stockItem, $qty);
141135
}
142136

@@ -148,12 +142,11 @@ public function checkQtyIncrements($productId, $qty, $websiteId = null)
148142
* @param int $scopeId
149143
* @return int
150144
*/
151-
public function checkQuoteItemQty($productId, $itemQty, $qtyToCheck, $origQty, $scopeId = null)
145+
public function checkQuoteItemQty($productId, $itemQty, $qtyToCheck, $origQty, $scopeId = null): int
152146
{
153-
// if ($scopeId === null) {
154-
$scopeId = $this->stockConfiguration->getDefaultScopeId();
155-
// }
147+
$scopeId = $this->stockConfiguration->getDefaultScopeId();
156148
$stockItem = $this->stockRegistryProvider->getStockItem($productId, $scopeId);
149+
157150
return $this->stockStateProvider->checkQuoteItemQty($stockItem, $itemQty, $qtyToCheck, $origQty);
158151
}
159152
}

0 commit comments

Comments
 (0)