Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
<?php /** * Copyright Magento, Inc. All rights reserved. * See COPYING.txt for license ..
Decoded Output download
<?php
/**
* Copyright Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\CatalogInventory\Model;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\CatalogInventory\Api\Data\StockItemInterface;
use Magento\CatalogInventory\Api\StockConfigurationInterface;
use Magento\CatalogInventory\Api\StockRegistryInterface;
use Magento\Framework\Exception\LocalizedException;
/**
* Validate Stock item
*/
class StockItemValidator
{
/**
* @var StockConfigurationInterface
*/
private $stockConfiguration;
/**
* @var StockRegistryInterface
*/
private $stockRegistry;
/**
* @param StockConfigurationInterface $stockConfiguration
* @param StockRegistryInterface $stockRegistry
*/
public function __construct(
StockConfigurationInterface $stockConfiguration,
StockRegistryInterface $stockRegistry
) {
$this->stockConfiguration = $stockConfiguration;
$this->stockRegistry = $stockRegistry;
}
/**
* Validate Stock item
*
* @param ProductInterface $product
* @param StockItemInterface $stockItem
* @throws LocalizedException
* @return void
*/
public function validate(ProductInterface $product, StockItemInterface $stockItem)
{
$defaultScopeId = $this->stockConfiguration->getDefaultScopeId();
$defaultStockId = $this->stockRegistry->getStock($defaultScopeId)->getStockId();
$stockId = $stockItem->getStockId();
if ($stockId !== null && $stockId != $defaultStockId) {
throw new LocalizedException(
__(
'The "%1" value is invalid for stock ID. Enter stock with a default value of %2 to try again.',
$stockId,
$defaultStockId
)
);
}
$stockItemId = $stockItem->getItemId();
if ($stockItemId !== null && (!is_numeric($stockItemId) || $stockItemId <= 0)) {
throw new LocalizedException(
__(
'The "%1" value is invalid for stock item ID. '
. 'Enter either null or a number greater than zero to try again.',
$stockItemId
)
);
}
$defaultStockItemId = $this->stockRegistry->getStockItem($product->getId())->getItemId();
if ($defaultStockItemId && $stockItemId !== null && $defaultStockItemId != $stockItemId) {
throw new LocalizedException(
__(
'The "%1" value is invalid for stock item ID. '
. 'Use the stock item ID\'s assigned "%2" value and try again.',
$stockItemId,
$defaultStockItemId
)
);
}
}
}
?>
Did this file decode correctly?
Original Code
<?php
/**
* Copyright Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\CatalogInventory\Model;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\CatalogInventory\Api\Data\StockItemInterface;
use Magento\CatalogInventory\Api\StockConfigurationInterface;
use Magento\CatalogInventory\Api\StockRegistryInterface;
use Magento\Framework\Exception\LocalizedException;
/**
* Validate Stock item
*/
class StockItemValidator
{
/**
* @var StockConfigurationInterface
*/
private $stockConfiguration;
/**
* @var StockRegistryInterface
*/
private $stockRegistry;
/**
* @param StockConfigurationInterface $stockConfiguration
* @param StockRegistryInterface $stockRegistry
*/
public function __construct(
StockConfigurationInterface $stockConfiguration,
StockRegistryInterface $stockRegistry
) {
$this->stockConfiguration = $stockConfiguration;
$this->stockRegistry = $stockRegistry;
}
/**
* Validate Stock item
*
* @param ProductInterface $product
* @param StockItemInterface $stockItem
* @throws LocalizedException
* @return void
*/
public function validate(ProductInterface $product, StockItemInterface $stockItem)
{
$defaultScopeId = $this->stockConfiguration->getDefaultScopeId();
$defaultStockId = $this->stockRegistry->getStock($defaultScopeId)->getStockId();
$stockId = $stockItem->getStockId();
if ($stockId !== null && $stockId != $defaultStockId) {
throw new LocalizedException(
__(
'The "%1" value is invalid for stock ID. Enter stock with a default value of %2 to try again.',
$stockId,
$defaultStockId
)
);
}
$stockItemId = $stockItem->getItemId();
if ($stockItemId !== null && (!is_numeric($stockItemId) || $stockItemId <= 0)) {
throw new LocalizedException(
__(
'The "%1" value is invalid for stock item ID. '
. 'Enter either null or a number greater than zero to try again.',
$stockItemId
)
);
}
$defaultStockItemId = $this->stockRegistry->getStockItem($product->getId())->getItemId();
if ($defaultStockItemId && $stockItemId !== null && $defaultStockItemId != $stockItemId) {
throw new LocalizedException(
__(
'The "%1" value is invalid for stock item ID. '
. 'Use the stock item ID\'s assigned "%2" value and try again.',
$stockItemId,
$defaultStockItemId
)
);
}
}
}
Function Calls
| None |
Stats
| MD5 | 7a0ff9e85bb1ac4217cea8c777466e6a |
| Eval Count | 0 |
| Decode Time | 119 ms |