From 246c1776dfb96bf49194f4fad487b84ed2e40bf4 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 16 Feb 2025 21:47:35 +0000 Subject: [PATCH] InventoryAction: avoid throwaway Item clones --- src/inventory/transaction/InventoryTransaction.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/inventory/transaction/InventoryTransaction.php b/src/inventory/transaction/InventoryTransaction.php index 8f7b576109..6e010c7b8f 100644 --- a/src/inventory/transaction/InventoryTransaction.php +++ b/src/inventory/transaction/InventoryTransaction.php @@ -144,8 +144,9 @@ protected function matchItems(array &$needItems, array &$haveItems) : void{ $needItems = []; $haveItems = []; foreach($this->actions as $key => $action){ - if(!$action->getTargetItem()->isNull()){ - $needItems[] = $action->getTargetItem(); + $targetItem = $action->getTargetItem(); + if(!$targetItem->isNull()){ + $needItems[] = $targetItem; } try{ @@ -154,8 +155,9 @@ protected function matchItems(array &$needItems, array &$haveItems) : void{ throw new TransactionValidationException(get_class($action) . "#" . spl_object_id($action) . ": " . $e->getMessage(), 0, $e); } - if(!$action->getSourceItem()->isNull()){ - $haveItems[] = $action->getSourceItem(); + $sourceItem = $action->getSourceItem(); + if(!$sourceItem->isNull()){ + $haveItems[] = $sourceItem; } }