Skip to content

Use constructor property promotion in module Sales Inventory #37230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 2.4-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 19 additions & 37 deletions app/code/Magento/SalesInventory/Model/Order/ReturnProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@
*/
namespace Magento\SalesInventory\Model\Order;

use Magento\Catalog\Model\Indexer\Product\Price\Processor as PriceProcessor;
use Magento\CatalogInventory\Api\StockManagementInterface;
use Magento\CatalogInventory\Model\Indexer\Stock\Processor as StockProcessor;
use Magento\Sales\Api\Data\CreditmemoInterface;
use Magento\Sales\Api\Data\CreditmemoItemInterface;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\OrderItemRepositoryInterface;
use Magento\Store\Model\StoreManagerInterface;

/**
* Class ReturnProcessor
Expand All @@ -17,50 +23,26 @@
class ReturnProcessor
{
/**
* @var \Magento\CatalogInventory\Api\StockManagementInterface
*/
private $stockManagement;

/**
* @var \Magento\CatalogInventory\Model\Indexer\Stock\Processor
* @var StockProcessor
*/
private $stockIndexerProcessor;

/**
* @var \Magento\Catalog\Model\Indexer\Product\Price\Processor
*/
private $priceIndexer;

/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
private $storeManager;

/**
* @var \Magento\Sales\Api\OrderItemRepositoryInterface
*/
private $orderItemRepository;

/**
* ReturnProcessor constructor.
* @param \Magento\CatalogInventory\Api\StockManagementInterface $stockManagement
* @param \Magento\CatalogInventory\Model\Indexer\Stock\Processor $stockIndexer
* @param \Magento\Catalog\Model\Indexer\Product\Price\Processor $priceIndexer
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Sales\Api\OrderItemRepositoryInterface $orderItemRepository
* @param StockManagementInterface $stockManagement
* @param StockProcessor $stockIndexer
* @param PriceProcessor $priceIndexer
* @param StoreManagerInterface $storeManager
* @param OrderItemRepositoryInterface $orderItemRepository
*/
public function __construct(
\Magento\CatalogInventory\Api\StockManagementInterface $stockManagement,
\Magento\CatalogInventory\Model\Indexer\Stock\Processor $stockIndexer,
\Magento\Catalog\Model\Indexer\Product\Price\Processor $priceIndexer,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Sales\Api\OrderItemRepositoryInterface $orderItemRepository
private readonly StockManagementInterface $stockManagement,
StockProcessor $stockIndexer,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why has this not been promoted?

Suggested change
StockProcessor $stockIndexer,
private readonly StockProcessor $stockIndexerProcessor,

private readonly PriceProcessor $priceIndexer,
private readonly StoreManagerInterface $storeManager,
private readonly OrderItemRepositoryInterface $orderItemRepository
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A trailing comma makes future additions easier to review.

Suggested change
private readonly OrderItemRepositoryInterface $orderItemRepository
private readonly OrderItemRepositoryInterface $orderItemRepository,

) {
$this->stockManagement = $stockManagement;
$this->stockIndexerProcessor = $stockIndexer;
$this->priceIndexer = $priceIndexer;
$this->storeManager = $storeManager;
$this->orderItemRepository = $orderItemRepository;
}

/**
Expand Down Expand Up @@ -109,14 +91,14 @@ public function execute(
}

/**
* @param \Magento\Sales\Api\Data\CreditmemoItemInterface $item
* @param CreditmemoItemInterface $item
* @param int $qty
* @param int[] $returnToStockItems
* @param int $parentItemId
* @return bool
*/
private function canReturnItem(
\Magento\Sales\Api\Data\CreditmemoItemInterface $item,
CreditmemoItemInterface $item,
$qty,
$parentItemId = null,
array $returnToStockItems = []
Expand Down
14 changes: 5 additions & 9 deletions app/code/Magento/SalesInventory/Model/Order/ReturnValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Magento\SalesInventory\Model\Order;

use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Phrase;
use Magento\Sales\Api\Data\CreditmemoInterface;
use Magento\Sales\Api\Data\CreditmemoItemInterface;
use Magento\Sales\Api\Data\OrderItemInterface;
Expand All @@ -16,24 +17,19 @@
*/
class ReturnValidator
{
/**
* @var OrderItemRepositoryInterface
*/
private $orderItemRepository;

/**
* ReturnValidator constructor.
* @param OrderItemRepositoryInterface $orderItemRepository
*/
public function __construct(OrderItemRepositoryInterface $orderItemRepository)
{
$this->orderItemRepository = $orderItemRepository;
public function __construct(
private readonly OrderItemRepositoryInterface $orderItemRepository
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A trailing comma makes future additions easier to review.

Suggested change
private readonly OrderItemRepositoryInterface $orderItemRepository
private readonly OrderItemRepositoryInterface $orderItemRepository,

) {
}

/**
* @param int[] $returnToStockItems
* @param CreditmemoInterface $creditmemo
* @return \Magento\Framework\Phrase|null
* @return Phrase|null
*/
public function validate($returnToStockItems, CreditmemoInterface $creditmemo)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
namespace Magento\SalesInventory\Model\Plugin\Order\Validation;

use Magento\Sales\Api\Data\CreditmemoCommentCreationInterface;
use Magento\Sales\Api\Data\InvoiceInterface;
use Magento\Sales\Model\Order\Validation\RefundInvoiceInterface;
use Magento\Sales\Api\Data\CreditmemoCreationArgumentsInterface;
Expand All @@ -18,19 +19,13 @@
*/
class InvoiceRefundCreationArguments
{
/**
* @var ReturnValidator
*/
private $returnValidator;

/**
* InvoiceRefundCreationArguments constructor.
* @param ReturnValidator $returnValidator
*/
public function __construct(
ReturnValidator $returnValidator
private readonly ReturnValidator $returnValidator
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A trailing comma makes future additions easier to review.

Suggested change
private readonly ReturnValidator $returnValidator
private readonly ReturnValidator $returnValidator,

) {
$this->returnValidator = $returnValidator;
}

/**
Expand All @@ -43,8 +38,8 @@ public function __construct(
* @param bool $isOnline
* @param bool $notify
* @param bool $appendComment
* @param \Magento\Sales\Api\Data\CreditmemoCommentCreationInterface|null $comment
* @param \Magento\Sales\Api\Data\CreditmemoCreationArgumentsInterface|null $arguments
* @param CreditmemoCommentCreationInterface|null $comment
* @param CreditmemoCreationArgumentsInterface|null $arguments
* @return ValidatorResultInterface
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
Expand All @@ -59,8 +54,8 @@ public function afterValidate(
$isOnline = false,
$notify = false,
$appendComment = false,
\Magento\Sales\Api\Data\CreditmemoCommentCreationInterface $comment = null,
\Magento\Sales\Api\Data\CreditmemoCreationArgumentsInterface $arguments = null
CreditmemoCommentCreationInterface $comment = null,
CreditmemoCreationArgumentsInterface $arguments = null
) {
if ($this->isReturnToStockItems($arguments)) {
return $validationResults;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,13 @@
*/
class OrderRefundCreationArguments
{
/**
* @var ReturnValidator
*/
private $returnValidator;

/**
* OrderRefundCreationArguments constructor.
* @param ReturnValidator $returnValidator
*/
public function __construct(
ReturnValidator $returnValidator
private readonly ReturnValidator $returnValidator
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A trailing comma makes future additions easier to review.

Suggested change
private readonly ReturnValidator $returnValidator
private readonly ReturnValidator $returnValidator,

) {
$this->returnValidator = $returnValidator;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@

namespace Magento\SalesInventory\Observer;

use Magento\Catalog\Model\Indexer\Product\Price\Processor as PriceProcessor;
use Magento\CatalogInventory\Api\StockConfigurationInterface;
use Magento\CatalogInventory\Api\StockManagementInterface;
use Magento\CatalogInventory\Model\Indexer\Stock\Processor as StockProcessor;
use Magento\Framework\Event\Observer as EventObserver;
use Magento\Framework\Event\ObserverInterface;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Model\Order\Creditmemo as OrderCreditmemo;
use Magento\SalesInventory\Model\Order\ReturnProcessor;

/**
Expand All @@ -18,59 +22,23 @@
*/
class RefundOrderInventoryObserver implements ObserverInterface
{
/**
* @var StockConfigurationInterface
*/
private $stockConfiguration;

/**
* @var StockManagementInterface
*/
private $stockManagement;

/**
* @var \Magento\CatalogInventory\Model\Indexer\Stock\Processor
*/
private $stockIndexerProcessor;

/**
* @var \Magento\Catalog\Model\Indexer\Product\Price\Processor
*/
private $priceIndexer;

/**
* @var \Magento\SalesInventory\Model\Order\ReturnProcessor
*/
private $returnProcessor;

/**
* @var \Magento\Sales\Api\OrderRepositoryInterface
*/
private $orderRepository;

/**
* RefundOrderInventoryObserver constructor.
* @param StockConfigurationInterface $stockConfiguration
* @param StockManagementInterface $stockManagement
* @param \Magento\CatalogInventory\Model\Indexer\Stock\Processor $stockIndexerProcessor
* @param \Magento\Catalog\Model\Indexer\Product\Price\Processor $priceIndexer
* @param StockProcessor $stockIndexerProcessor
* @param PriceProcessor $priceIndexer
* @param ReturnProcessor $returnProcessor
* @param \Magento\Sales\Api\OrderRepositoryInterface $orderRepository
* @param OrderRepositoryInterface $orderRepository
*/
public function __construct(
StockConfigurationInterface $stockConfiguration,
StockManagementInterface $stockManagement,
\Magento\CatalogInventory\Model\Indexer\Stock\Processor $stockIndexerProcessor,
\Magento\Catalog\Model\Indexer\Product\Price\Processor $priceIndexer,
\Magento\SalesInventory\Model\Order\ReturnProcessor $returnProcessor,
\Magento\Sales\Api\OrderRepositoryInterface $orderRepository
private readonly StockConfigurationInterface $stockConfiguration,
private readonly StockManagementInterface $stockManagement,
private readonly StockProcessor $stockIndexerProcessor,
private readonly PriceProcessor $priceIndexer,
private readonly ReturnProcessor $returnProcessor,
private readonly OrderRepositoryInterface $orderRepository
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A trailing comma makes future additions easier to review.

Suggested change
private readonly OrderRepositoryInterface $orderRepository
private readonly OrderRepositoryInterface $orderRepository,

) {
$this->stockConfiguration = $stockConfiguration;
$this->stockManagement = $stockManagement;
$this->stockIndexerProcessor = $stockIndexerProcessor;
$this->priceIndexer = $priceIndexer;
$this->returnProcessor = $returnProcessor;
$this->orderRepository = $orderRepository;
}

/**
Expand All @@ -81,7 +49,7 @@ public function __construct(
*/
public function execute(EventObserver $observer)
{
/* @var $creditmemo \Magento\Sales\Model\Order\Creditmemo */
/* @var OrderCreditmemo $creditmemo */
$creditmemo = $observer->getEvent()->getCreditmemo();
$order = $this->orderRepository->get($creditmemo->getOrderId());
$returnToStockItems = [];
Expand Down
6 changes: 5 additions & 1 deletion app/code/Magento/SalesInventory/registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@

use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_SalesInventory', __DIR__);
ComponentRegistrar::register(
ComponentRegistrar::MODULE,
'Magento_SalesInventory',
__DIR__
);