Skip to content

Commit 502d66e

Browse files
committed
#23191 Fix static tests
We have to ignore the CyclomaticComplexity of 11 of \Magento\CatalogImportExport\Model\Import\Product\LinkProcessor::processLinkBunches It's since we added the if() to check for empty links. I do not find a easy way to reduce it, because the if contains a continue statement.
1 parent 11c3525 commit 502d66e

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Product/LinkProcessor.php

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
use Psr\Log\LoggerInterface;
1616

1717
/**
18-
* Class LinkProcessor
18+
* Processor for links between products
19+
*
20+
* Remark: Via DI it is possible to supply additional link types.
1921
*/
2022
class LinkProcessor
2123
{
@@ -76,7 +78,7 @@ public function __construct(
7678
* @param Product $importEntity
7779
* @param Data $dataSourceModel
7880
* @param string $linkField
79-
* @return $this
81+
* @return void
8082
* @throws LocalizedException
8183
*/
8284
public function saveLinks(
@@ -128,6 +130,7 @@ public function addNameToIds(array $nameToIds): void
128130
*
129131
* @return void
130132
* @throws LocalizedException
133+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
131134
*/
132135
private function processLinkBunches(
133136
Product $importEntity,
@@ -163,6 +166,7 @@ function ($linkName) use ($rowData) {
163166
$linksToDelete[$linkId][] = $productId;
164167
continue;
165168
}
169+
166170
$linkPositions = ! empty($rowData[$linkName . 'position'])
167171
? explode($importEntity->getMultipleValueSeparator(), $rowData[$linkName . 'position'])
168172
: [];
@@ -180,7 +184,7 @@ function ($linkedSku) use ($sku, $importEntity) {
180184
}
181185
);
182186
foreach ($linkSkus as $linkedKey => $linkedSku) {
183-
$linkedId = $this->getProductLinkedId($linkedSku);
187+
$linkedId = $this->getProductLinkedId($importEntity, $linkedSku);
184188
if ($linkedId == null) {
185189
// Import file links to a SKU which is skipped for some reason, which leads to a "NULL"
186190
// link causing fatal errors.
@@ -259,6 +263,19 @@ private function isSkuExist(Product $importEntity, string $sku): bool
259263
return isset($importEntity->getOldSku()[$sku]);
260264
}
261265

266+
/**
267+
* Get existing SKU record
268+
*
269+
* @param Product $importEntity
270+
* @param string $sku
271+
* @return mixed
272+
*/
273+
private function getExistingSku(Product $importEntity, string $sku)
274+
{
275+
$sku = strtolower($sku);
276+
return $importEntity->getOldSku()[$sku];
277+
}
278+
262279
/**
263280
* Fetches Product Links
264281
*
@@ -289,15 +306,18 @@ private function fetchProductLinks(Product $importEntity, Link $resource, int $p
289306
/**
290307
* Gets the Id of the Sku
291308
*
309+
* @param Product $importEntity
292310
* @param string $linkedSku
293-
*
294311
* @return int|null
295312
*/
296-
private function getProductLinkedId(string $linkedSku): ?int
313+
private function getProductLinkedId(Product $importEntity, string $linkedSku): ?int
297314
{
298315
$linkedSku = trim($linkedSku);
299316
$newSku = $this->skuProcessor->getNewSku($linkedSku);
300-
$linkedId = ! empty($newSku) ? $newSku['entity_id'] : $this->getExistingSku($linkedSku)['entity_id'];
317+
318+
$linkedId = ! empty($newSku) ?
319+
$newSku['entity_id'] :
320+
$this->getExistingSku($importEntity, $linkedSku)['entity_id'];
301321

302322
return $linkedId;
303323
}

0 commit comments

Comments
 (0)