Skip to content

lf#36

Open
IrmaKarasoftic wants to merge 1 commit intomainfrom
file-size-issue-1
Open

lf#36
IrmaKarasoftic wants to merge 1 commit intomainfrom
file-size-issue-1

Conversation

@IrmaKarasoftic
Copy link
Owner

No description provided.

Copy link

Choose a reason for hiding this comment

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

Quality Gates: FAILED

  • Declining Code Health: 35 findings(s) 🚩
  • Improving Code Health: 0 findings(s) ✅
  • Affected Hotspots: 0 files(s) 🔥

Recommended Review Level: Detailed -- Inspect the code that degrades in code health.
View detailed results in CodeScene

🚩 Negative Code Health Impact (highest to lowest):

Copy link

Choose a reason for hiding this comment

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

Quality Gates: FAILED

  • Declining Code Health: 35 findings(s) 🚩
  • Improving Code Health: 0 findings(s) ✅
  • Affected Hotspots: 0 files(s) 🔥

Recommended Review Level: Detailed -- Inspect the code that degrades in code health.
View detailed results in CodeScene

🚩 Negative Code Health Impact (highest to lowest):

Copy link

Choose a reason for hiding this comment

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

Quality Gates: FAILED

  • Declining Code Health: 35 findings(s) 🚩
  • Improving Code Health: 0 findings(s) ✅
  • Affected Hotspots: 0 files(s) 🔥

Recommended Review Level: Detailed -- Inspect the code that degrades in code health.
View detailed results in CodeScene

🚩 Negative Code Health Impact (highest to lowest):

Copy link

Choose a reason for hiding this comment

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

Quality Gates: FAILED

  • Declining Code Health: 35 findings(s) 🚩
  • Improving Code Health: 0 findings(s) ✅
  • Affected Hotspots: 0 files(s) 🔥

Recommended Review Level: Detailed -- Inspect the code that degrades in code health.
View detailed results in CodeScene

🚩 Negative Code Health Impact (highest to lowest):

Copy link

Choose a reason for hiding this comment

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

Quality Gates: FAILED

  • Declining Code Health: 35 findings(s) 🚩
  • Improving Code Health: 0 findings(s) ✅
  • Affected Hotspots: 0 files(s) 🔥

Recommended Review Level: Detailed -- Inspect the code that degrades in code health.
View detailed results in CodeScene

🚩 Negative Code Health Impact (highest to lowest):

Copy link

Choose a reason for hiding this comment

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

Quality Gates: FAILED

  • Declining Code Health: 35 findings(s) 🚩
  • Improving Code Health: 0 findings(s) ✅
  • Affected Hotspots: 0 files(s) 🔥

Recommended Review Level: Detailed -- Inspect the code that degrades in code health.
View detailed results in CodeScene

🚩 Negative Code Health Impact (highest to lowest):

Copy link

Choose a reason for hiding this comment

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

Quality Gates: FAILED

  • Declining Code Health: 35 findings(s) 🚩
  • Improving Code Health: 0 findings(s) ✅
  • Affected Hotspots: 0 files(s) 🔥

Recommended Review Level: Detailed -- Inspect the code that degrades in code health.
View detailed results in CodeScene

🚩 Negative Code Health Impact (highest to lowest):

Copy link

Choose a reason for hiding this comment

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

Quality Gates: FAILED

  • Declining Code Health: 35 findings(s) 🚩
  • Improving Code Health: 0 findings(s) ✅
  • Affected Hotspots: 0 files(s) 🔥

Recommended Review Level: Detailed -- Inspect the code that degrades in code health.
View detailed results in CodeScene

🚩 Negative Code Health Impact (highest to lowest):

Copy link

Choose a reason for hiding this comment

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

Quality Gates: FAILED

  • Declining Code Health: 35 findings(s) 🚩
  • Improving Code Health: 0 findings(s) ✅
  • Affected Hotspots: 0 files(s) 🔥

Recommended Review Level: Detailed -- Inspect the code that degrades in code health.
View detailed results in CodeScene

🚩 Negative Code Health Impact (highest to lowest):

Copy link

Choose a reason for hiding this comment

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

Quality Gates: FAILED

  • Declining Code Health: 35 findings(s) 🚩
  • Improving Code Health: 0 findings(s) ✅
  • Affected Hotspots: 0 files(s) 🔥

Recommended Review Level: Detailed -- Inspect the code that degrades in code health.
View detailed results in CodeScene

🚩 Negative Code Health Impact (highest to lowest):

Copy link

Choose a reason for hiding this comment

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

Quality Gates: FAILED

  • Declining Code Health: 35 findings(s) 🚩
  • Improving Code Health: 0 findings(s) ✅
  • Affected Hotspots: 0 files(s) 🔥

Recommended Review Level: Detailed -- Inspect the code that degrades in code health.
View detailed results in CodeScene

🚩 Negative Code Health Impact (highest to lowest):

Copy link

Choose a reason for hiding this comment

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

Quality Gates: FAILED

  • Declining Code Health: 35 findings(s) 🚩
  • Improving Code Health: 0 findings(s) ✅
  • Affected Hotspots: 0 files(s) 🔥

Recommended Review Level: Detailed -- Inspect the code that degrades in code health.
View detailed results in CodeScene

🚩 Negative Code Health Impact (highest to lowest):

Copy link

Choose a reason for hiding this comment

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

Quality Gates: FAILED

  • Declining Code Health: 35 findings(s) 🚩
  • Improving Code Health: 0 findings(s) ✅
  • Affected Hotspots: 0 files(s) 🔥

Recommended Review Level: Detailed -- Inspect the code that degrades in code health.
View detailed results in CodeScene

🚩 Negative Code Health Impact (highest to lowest):

Copy link

Choose a reason for hiding this comment

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

Quality Gates: FAILED

  • Declining Code Health: 35 findings(s) 🚩
  • Improving Code Health: 0 findings(s) ✅
  • Affected Hotspots: 0 files(s) 🔥

Recommended Review Level: Detailed -- Inspect the code that degrades in code health.
View detailed results in CodeScene

🚩 Negative Code Health Impact (highest to lowest):

Copy link

Choose a reason for hiding this comment

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

Code Health Quality Gates: FAILED

  • Declining Code Health: 35 findings(s) 🚩
  • Improving Code Health: 0 findings(s) ✅
  • Affected Hotspots: 0 files(s) 🔥

Recommended Review Level: Detailed -- Inspect the code that degrades in code health.
View detailed results in CodeScene

🚩 Declining Code Health (highest to lowest):

Copy link

@codescene-app-cloud codescene-app-cloud bot left a comment

Choose a reason for hiding this comment

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

Code Health Quality Gates: FAILED

  • Declining Code Health: 34 findings(s) 🚩
  • Improving Code Health: 0 findings(s) ✅
  • Affected Hotspots: 0 files(s) 🔥

Recommended Review Level: Detailed -- Inspect the code that degrades in code health.
View detailed results in CodeScene

🚩 Declining Code Health (highest to lowest):

var categoryBreadCrumb = category.GetFormattedBreadCrumb(_categoryService);
if (!allCategories.ContainsKey(categoryBreadCrumb))
allCategories.Add(categoryBreadCrumb, category);
if (!string.IsNullOrEmpty(curentCategoryBreadCrumb) && allCategories.ContainsKey(curentCategoryBreadCrumb) &&

Choose a reason for hiding this comment

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

❌ New issue: Complex Conditional
SaveCategory has 1 complex conditionals with 2 branches, threshold = 2

Why does this problem occur?

A complex conditional is an expression inside a branch (e.g. if, for, while) which consists of multiple, logical operators such as AND/OR. The more logical operators in an expression, the more severe the code smell. Read more.

To ignore this warning click here.


protected virtual void ImportProductAttribute(PropertyManager<ExportProductAttribute> productAttributeManager, Product lastLoadedProduct)
{
if (!_catalogSettings.ExportImportProductAttributes || lastLoadedProduct == null || productAttributeManager.IsCaption)

Choose a reason for hiding this comment

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

❌ New issue: Complex Conditional
ImportProductAttribute has 1 complex conditionals with 2 branches, threshold = 2

Why does this problem occur?

A complex conditional is an expression inside a branch (e.g. if, for, while) which consists of multiple, logical operators such as AND/OR. The more logical operators in an expression, the more severe the code smell. Read more.

To ignore this warning click here.


private void ImportSpecificationAttribute(PropertyManager<ExportSpecificationAttribute> specificationAttributeManager, Product lastLoadedProduct)
{
if (!_catalogSettings.ExportImportProductSpecificationAttributes || lastLoadedProduct == null || specificationAttributeManager.IsCaption)

Choose a reason for hiding this comment

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

❌ New issue: Complex Conditional
ImportSpecificationAttribute has 1 complex conditionals with 2 branches, threshold = 2

Why does this problem occur?

A complex conditional is an expression inside a branch (e.g. if, for, while) which consists of multiple, logical operators such as AND/OR. The more logical operators in an expression, the more severe the code smell. Read more.

To ignore this warning click here.

//_productService.UpdateHasDiscountsApplied(product);
}

if (_mediaSettings.ImportProductImagesUsingHash && _pictureService.StoreInDb && _dataProvider.SupportedLengthOfBinaryHash() > 0)

Choose a reason for hiding this comment

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

❌ New issue: Complex Conditional
ImportProductsFromXlsx has 1 complex conditionals with 2 branches, threshold = 2

Why does this problem occur?

A complex conditional is an expression inside a branch (e.g. if, for, while) which consists of multiple, logical operators such as AND/OR. The more logical operators in an expression, the more severe the code smell. Read more.

To ignore this warning click here.

Comment on lines +2141 to +2142
if ((StoresIds.Any() || y.StoresIds.Any())
&& (StoresIds.All(id => !y.StoresIds.Contains(id)) || y.StoresIds.All(id => !StoresIds.Contains(id))))

Choose a reason for hiding this comment

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

❌ New issue: Complex Conditional
Equals has 1 complex conditionals with 3 branches, threshold = 2

Why does this problem occur?

A complex conditional is an expression inside a branch (e.g. if, for, while) which consists of multiple, logical operators such as AND/OR. The more logical operators in an expression, the more severe the code smell. Read more.

To ignore this warning click here.

Comment on lines +381 to +481
{
var seName = string.Empty;
isParentCategoryExists = true;
var isParentCategorySet = false;

foreach (var property in manager.GetProperties)
{
switch (property.PropertyName)
{
case "Name":
category.Name = property.StringValue.Split(new[] { ">>" }, StringSplitOptions.RemoveEmptyEntries).Last().Trim();
break;
case "Description":
category.Description = property.StringValue;
break;
case "CategoryTemplateId":
category.CategoryTemplateId = property.IntValue;
break;
case "MetaKeywords":
category.MetaKeywords = property.StringValue;
break;
case "MetaDescription":
category.MetaDescription = property.StringValue;
break;
case "MetaTitle":
category.MetaTitle = property.StringValue;
break;
case "ParentCategoryId":
if (!isParentCategorySet)
{
var parentCategory = allCategories.Values.FirstOrDefault(c => c.Id == property.IntValue);
isParentCategorySet = parentCategory != null;

isParentCategoryExists = isParentCategorySet || property.IntValue == 0;

category.ParentCategoryId = parentCategory?.Id ?? property.IntValue;
}
break;
case "ParentCategoryName":
if (_catalogSettings.ExportImportCategoriesUsingCategoryName && !isParentCategorySet)
{
var categoryName = manager.GetProperty("ParentCategoryName").StringValue;
if (!string.IsNullOrEmpty(categoryName))
{
var parentCategory = allCategories.ContainsKey(categoryName)
//try find category by full name with all parent category names
? allCategories[categoryName]
//try find category by name
: allCategories.Values.FirstOrDefault(c => c.Name.Equals(categoryName, StringComparison.InvariantCulture));

if (parentCategory != null)
{
category.ParentCategoryId = parentCategory.Id;
isParentCategorySet = true;
}
else
{
isParentCategoryExists = false;
}
}
}
break;
case "Picture":
var picture = LoadPicture(manager.GetProperty("Picture").StringValue, category.Name, isNew ? null : (int?)category.PictureId);
if (picture != null)
category.PictureId = picture.Id;
break;
case "PageSize":
category.PageSize = property.IntValue;
break;
case "AllowCustomersToSelectPageSize":
category.AllowCustomersToSelectPageSize = property.BooleanValue;
break;
case "PageSizeOptions":
category.PageSizeOptions = property.StringValue;
break;
case "PriceRanges":
category.PriceRanges = property.StringValue;
break;
case "ShowOnHomePage":
category.ShowOnHomePage = property.BooleanValue;
break;
case "IncludeInTopMenu":
category.IncludeInTopMenu = property.BooleanValue;
break;
case "Published":
category.Published = property.BooleanValue;
break;
case "DisplayOrder":
category.DisplayOrder = property.IntValue;
break;
case "SeName":
seName = property.StringValue;
break;
}
}

category.UpdatedOnUtc = DateTime.UtcNow;
return seName;
}

Choose a reason for hiding this comment

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

❌ New issue: Deep, Nested Complexity
UpdateCategoryByXlsx has a nested complexity depth of 5, threshold = 4

Why does this problem occur?

This function contains deeply nested logic such as if statements and/or loops. The deeper the nesting, the lower the code health. Read more.

To ignore this warning click here.

Comment on lines +789 to +1035
out int aid))
{
allAttributeIds.Add(aid);
}
else
{
specificationAttributeManager.ReadFromXlsx(worksheet, endRow,
ExportProductAttribute.ProducAttributeCellOffset);

if (!specificationAttributeManager.IsCaption &&
int.TryParse(
(worksheet.Cells[endRow, specificationAttributeOptionIdCellNum].Value ??
string.Empty).ToString(), out int saoid))
{
allSpecificationAttributeOptionIds.Add(saoid);
}
}
}

endRow++;
continue;
}

if (categoryCellNum > 0)
{
var categoryIds = worksheet.Cells[endRow, categoryCellNum].Value?.ToString() ?? string.Empty;

if (!string.IsNullOrEmpty(categoryIds))
allCategoriesNames.AddRange(categoryIds
.Split(new[] { ";", ">>" }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim())
.Distinct());
}

if (skuCellNum > 0)
{
var sku = worksheet.Cells[endRow, skuCellNum].Value?.ToString() ?? string.Empty;

if (!string.IsNullOrEmpty(sku))
allSku.Add(sku);
}

if (manufacturerCellNum > 0)
{
var manufacturerIds = worksheet.Cells[endRow, manufacturerCellNum].Value?.ToString() ??
string.Empty;
if (!string.IsNullOrEmpty(manufacturerIds))
allManufacturersNames.AddRange(manufacturerIds
.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()));
}

//counting the number of products
productsInFile.Add(endRow);

endRow++;
}

//performance optimization, the check for the existence of the categories in one SQL request
var notExistingCategories = _categoryService.GetNotExistingCategories(allCategoriesNames.ToArray());
if (notExistingCategories.Any())
{
throw new ArgumentException(string.Format(_localizationService.GetResource("Admin.Catalog.Products.Import.CategoriesDontExist"), string.Join(", ", notExistingCategories)));
}

//performance optimization, the check for the existence of the manufacturers in one SQL request
var notExistingManufacturers = _manufacturerService.GetNotExistingManufacturers(allManufacturersNames.ToArray());
if (notExistingManufacturers.Any())
{
throw new ArgumentException(string.Format(_localizationService.GetResource("Admin.Catalog.Products.Import.ManufacturersDontExist"), string.Join(", ", notExistingManufacturers)));
}

//performance optimization, the check for the existence of the product attributes in one SQL request
var notExistingProductAttributes = _productAttributeService.GetNotExistingAttributes(allAttributeIds.ToArray());
if (notExistingProductAttributes.Any())
{
throw new ArgumentException(string.Format(_localizationService.GetResource("Admin.Catalog.Products.Import.ProductAttributesDontExist"), string.Join(", ", notExistingProductAttributes)));
}

//performance optimization, the check for the existence of the specification attribute options in one SQL request
var notExistingSpecificationAttributeOptions = _specificationAttributeService.GetNotExistingSpecificationAttributeOptions(allSpecificationAttributeOptionIds.Where(saoId => saoId != 0).ToArray());
if (notExistingSpecificationAttributeOptions.Any())
{
throw new ArgumentException($"The following specification attribute option ID(s) don't exist - {string.Join(", ", notExistingSpecificationAttributeOptions)}");
}

return new ImportProductMetadata
{
EndRow = endRow,
Manager = manager,
Properties = properties,
ProductsInFile = productsInFile,
ProductAttributeManager = productAttributeManager,
SpecificationAttributeManager = specificationAttributeManager,
SkuCellNum = skuCellNum,
AllSku = allSku,
AllCategoriesNames = allCategoriesNames,
AllManufacturersNames = allManufacturersNames,
AllAttributeIds = allAttributeIds,
AllSpecificationAttributeOptionIds = allSpecificationAttributeOptionIds
};
}

Choose a reason for hiding this comment

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

❌ New issue: Deep, Nested Complexity
PrepareImportProductData has a nested complexity depth of 5, threshold = 4

Why does this problem occur?

This function contains deeply nested logic such as if statements and/or loops. The deeper the nesting, the lower the code health. Read more.

To ignore this warning click here.

Comment on lines +1164 to +1728
IsFeaturedProduct = false,
DisplayOrder = 1
};
_categoryService.InsertProductCategory(productCategory);
}

//delete product categories
var deletedProductCategories = categories.Where(categoryId => !importedCategories.Contains(categoryId))
.Select(categoryId => product.ProductCategories.First(pc => pc.CategoryId == categoryId));
foreach (var deletedProductCategory in deletedProductCategories)
{
_categoryService.DeleteProductCategory(deletedProductCategory);
}
}

tempProperty = metadata.Manager.GetProperty("Manufacturers");
if (tempProperty != null)
{
var manufacturerNames = tempProperty.StringValue;

//manufacturer mappings
var manufacturers = isNew || !allProductsManufacturerIds.ContainsKey(product.Id) ? new int[0] : allProductsManufacturerIds[product.Id];
var importedManufacturers = manufacturerNames.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(x => allManufacturers.First(m => m.Name == x.Trim()).Id).ToList();
foreach (var manufacturerId in importedManufacturers)
{
if (manufacturers.Any(c => c == manufacturerId))
continue;

var productManufacturer = new ProductManufacturer
{
ProductId = product.Id,
ManufacturerId = manufacturerId,
IsFeaturedProduct = false,
DisplayOrder = 1
};
_manufacturerService.InsertProductManufacturer(productManufacturer);
}

//delete product manufacturers
var deletedProductsManufacturers = manufacturers.Where(manufacturerId => !importedManufacturers.Contains(manufacturerId))
.Select(manufacturerId => product.ProductManufacturers.First(pc => pc.ManufacturerId == manufacturerId));
foreach (var deletedProductManufacturer in deletedProductsManufacturers)
{
_manufacturerService.DeleteProductManufacturer(deletedProductManufacturer);
}
}

tempProperty = metadata.Manager.GetProperty("ProductTags");
if (tempProperty != null)
{
var productTags = tempProperty.StringValue.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToArray();

//product tag mappings
_productTagService.UpdateProductTags(product, productTags);
}

var picture1 = DownloadFile(metadata.Manager.GetProperty("Picture1")?.StringValue, downloadedFiles);
var picture2 = DownloadFile(metadata.Manager.GetProperty("Picture2")?.StringValue, downloadedFiles);
var picture3 = DownloadFile(metadata.Manager.GetProperty("Picture3")?.StringValue, downloadedFiles);

productPictureMetadata.Add(new ProductPictureMetadata
{
ProductItem = product,
Picture1Path = picture1,
Picture2Path = picture2,
Picture3Path = picture3,
IsNew = isNew
});

lastLoadedProduct = product;

//update "HasTierPrices" and "HasDiscountsApplied" properties
//_productService.UpdateHasTierPricesProperty(product);
//_productService.UpdateHasDiscountsApplied(product);
}

if (_mediaSettings.ImportProductImagesUsingHash && _pictureService.StoreInDb && _dataProvider.SupportedLengthOfBinaryHash() > 0)
ImportProductImagesUsingHash(productPictureMetadata, allProductsBySku);
else
ImportProductImagesUsingServices(productPictureMetadata);

foreach (var downloadedFile in downloadedFiles)
{
if (!_fileProvider.FileExists(downloadedFile))
continue;

try
{
_fileProvider.DeleteFile(downloadedFile);
}
catch
{

}
}

//activity log
_customerActivityService.InsertActivity("ImportProducts", string.Format(_localizationService.GetResource("ActivityLog.ImportProducts"), metadata.CountProductsInFile));
}
}

Choose a reason for hiding this comment

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

❌ New issue: Deep, Nested Complexity
ImportProductsFromXlsx has a nested complexity depth of 4, threshold = 4

Why does this problem occur?

This function contains deeply nested logic such as if statements and/or loops. The deeper the nesting, the lower the code health. Read more.

To ignore this warning click here.

Comment on lines +1873 to +1991
var allColumnsAreEmpty = manager.GetProperties
.Select(property => worksheet.Cells[iRow, property.PropertyOrderPosition])
.All(cell => cell == null || cell.Value == null || string.IsNullOrEmpty(cell.Value.ToString()));

if (allColumnsAreEmpty)
break;

manager.ReadFromXlsx(worksheet, iRow);

var manufacturer = _manufacturerService.GetManufacturerById(manager.GetProperty("Id").IntValue);

var isNew = manufacturer == null;

manufacturer = manufacturer ?? new Manufacturer();

if (isNew)
{
manufacturer.CreatedOnUtc = DateTime.UtcNow;

//default values
manufacturer.PageSize = _catalogSettings.DefaultManufacturerPageSize;
manufacturer.PageSizeOptions = _catalogSettings.DefaultManufacturerPageSizeOptions;
manufacturer.Published = true;
manufacturer.AllowCustomersToSelectPageSize = true;
}

var seName = string.Empty;

foreach (var property in manager.GetProperties)
{
switch (property.PropertyName)
{
case "Name":
manufacturer.Name = property.StringValue;
break;
case "Description":
manufacturer.Description = property.StringValue;
break;
case "ManufacturerTemplateId":
manufacturer.ManufacturerTemplateId = property.IntValue;
break;
case "MetaKeywords":
manufacturer.MetaKeywords = property.StringValue;
break;
case "MetaDescription":
manufacturer.MetaDescription = property.StringValue;
break;
case "MetaTitle":
manufacturer.MetaTitle = property.StringValue;
break;
case "Picture":
var picture = LoadPicture(manager.GetProperty("Picture").StringValue, manufacturer.Name, isNew ? null : (int?)manufacturer.PictureId);

if (picture != null)
manufacturer.PictureId = picture.Id;

break;
case "PageSize":
manufacturer.PageSize = property.IntValue;
break;
case "AllowCustomersToSelectPageSize":
manufacturer.AllowCustomersToSelectPageSize = property.BooleanValue;
break;
case "PageSizeOptions":
manufacturer.PageSizeOptions = property.StringValue;
break;
case "PriceRanges":
manufacturer.PriceRanges = property.StringValue;
break;
case "Published":
manufacturer.Published = property.BooleanValue;
break;
case "DisplayOrder":
manufacturer.DisplayOrder = property.IntValue;
break;
case "SeName":
seName = property.StringValue;
break;
}
}

manufacturer.UpdatedOnUtc = DateTime.UtcNow;

if (isNew)
_manufacturerService.InsertManufacturer(manufacturer);
else
_manufacturerService.UpdateManufacturer(manufacturer);

//search engine name
if (setSeName)
_urlRecordService.SaveSlug(manufacturer, manufacturer.ValidateSeName(seName, manufacturer.Name, true), 0);

iRow++;
}

//activity log
_customerActivityService.InsertActivity("ImportManufacturers",
string.Format(_localizationService.GetResource("ActivityLog.ImportManufacturers"), iRow - 2));
}
}

Choose a reason for hiding this comment

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

❌ New issue: Deep, Nested Complexity
ImportManufacturersFromXlsx has a nested complexity depth of 4, threshold = 4

Why does this problem occur?

This function contains deeply nested logic such as if statements and/or loops. The deeper the nesting, the lower the code health. Read more.

To ignore this warning click here.

@@ -0,0 +1,2170 @@
using System;

Choose a reason for hiding this comment

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

❌ New issue: Low Cohesion
This module has at least 4 different responsibilities amongst its 32 functions, threshold = 3

Why does this problem occur?

Cohesion is calculated using the LCOM4 metric. Low cohesion means that the module/class has multiple unrelated responsibilities, doing too many things and breaking the Single Responsibility Principle. Read more.

To ignore this warning click here.

Copy link

@codescene-app-cloud codescene-app-cloud bot left a comment

Choose a reason for hiding this comment

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

Code Health Quality Gates: FAILED

  • Declining Code Health: 34 findings(s) 🚩
  • Improving Code Health: 0 findings(s) ✅
  • Affected Hotspots: 0 files(s) 🔥

Recommended Review Level: Detailed -- Inspect the code that degrades in code health.
View detailed results in CodeScene

🚩 Declining Code Health (highest to lowest):

Copy link

Choose a reason for hiding this comment

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

Code Health Quality Gates: FAILED

  • Declining Code Health: 34 findings(s) 🚩
  • Improving Code Health: 0 findings(s) ✅
  • Affected Hotspots: 0 files(s) 🔥

Recommended Review Level: Detailed -- Inspect the code that degrades in code health.
View detailed results in CodeScene

🚩 Declining Code Health (highest to lowest):

var categoryBreadCrumb = category.GetFormattedBreadCrumb(_categoryService);
if (!allCategories.ContainsKey(categoryBreadCrumb))
allCategories.Add(categoryBreadCrumb, category);
if (!string.IsNullOrEmpty(curentCategoryBreadCrumb) && allCategories.ContainsKey(curentCategoryBreadCrumb) &&

Choose a reason for hiding this comment

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

❌ New issue: Complex Conditional
SaveCategory has 1 complex conditionals with 2 branches, threshold = 2

Why does this problem occur?

A complex conditional is an expression inside a branch (e.g. if, for, while) which consists of multiple, logical operators such as AND/OR. The more logical operators in an expression, the more severe the code smell. Read more.

To ignore this warning click here.


protected virtual void ImportProductAttribute(PropertyManager<ExportProductAttribute> productAttributeManager, Product lastLoadedProduct)
{
if (!_catalogSettings.ExportImportProductAttributes || lastLoadedProduct == null || productAttributeManager.IsCaption)

Choose a reason for hiding this comment

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

❌ New issue: Complex Conditional
ImportProductAttribute has 1 complex conditionals with 2 branches, threshold = 2

Why does this problem occur?

A complex conditional is an expression inside a branch (e.g. if, for, while) which consists of multiple, logical operators such as AND/OR. The more logical operators in an expression, the more severe the code smell. Read more.

To ignore this warning click here.


private void ImportSpecificationAttribute(PropertyManager<ExportSpecificationAttribute> specificationAttributeManager, Product lastLoadedProduct)
{
if (!_catalogSettings.ExportImportProductSpecificationAttributes || lastLoadedProduct == null || specificationAttributeManager.IsCaption)

Choose a reason for hiding this comment

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

❌ New issue: Complex Conditional
ImportSpecificationAttribute has 1 complex conditionals with 2 branches, threshold = 2

Why does this problem occur?

A complex conditional is an expression inside a branch (e.g. if, for, while) which consists of multiple, logical operators such as AND/OR. The more logical operators in an expression, the more severe the code smell. Read more.

To ignore this warning click here.

//_productService.UpdateHasDiscountsApplied(product);
}

if (_mediaSettings.ImportProductImagesUsingHash && _pictureService.StoreInDb && _dataProvider.SupportedLengthOfBinaryHash() > 0)

Choose a reason for hiding this comment

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

❌ New issue: Complex Conditional
ImportProductsFromXlsx has 1 complex conditionals with 2 branches, threshold = 2

Why does this problem occur?

A complex conditional is an expression inside a branch (e.g. if, for, while) which consists of multiple, logical operators such as AND/OR. The more logical operators in an expression, the more severe the code smell. Read more.

To ignore this warning click here.

Comment on lines +2141 to +2142
if ((StoresIds.Any() || y.StoresIds.Any())
&& (StoresIds.All(id => !y.StoresIds.Contains(id)) || y.StoresIds.All(id => !StoresIds.Contains(id))))

Choose a reason for hiding this comment

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

❌ New issue: Complex Conditional
Equals has 1 complex conditionals with 3 branches, threshold = 2

Why does this problem occur?

A complex conditional is an expression inside a branch (e.g. if, for, while) which consists of multiple, logical operators such as AND/OR. The more logical operators in an expression, the more severe the code smell. Read more.

To ignore this warning click here.

Comment on lines +381 to +481
{
var seName = string.Empty;
isParentCategoryExists = true;
var isParentCategorySet = false;

foreach (var property in manager.GetProperties)
{
switch (property.PropertyName)
{
case "Name":
category.Name = property.StringValue.Split(new[] { ">>" }, StringSplitOptions.RemoveEmptyEntries).Last().Trim();
break;
case "Description":
category.Description = property.StringValue;
break;
case "CategoryTemplateId":
category.CategoryTemplateId = property.IntValue;
break;
case "MetaKeywords":
category.MetaKeywords = property.StringValue;
break;
case "MetaDescription":
category.MetaDescription = property.StringValue;
break;
case "MetaTitle":
category.MetaTitle = property.StringValue;
break;
case "ParentCategoryId":
if (!isParentCategorySet)
{
var parentCategory = allCategories.Values.FirstOrDefault(c => c.Id == property.IntValue);
isParentCategorySet = parentCategory != null;

isParentCategoryExists = isParentCategorySet || property.IntValue == 0;

category.ParentCategoryId = parentCategory?.Id ?? property.IntValue;
}
break;
case "ParentCategoryName":
if (_catalogSettings.ExportImportCategoriesUsingCategoryName && !isParentCategorySet)
{
var categoryName = manager.GetProperty("ParentCategoryName").StringValue;
if (!string.IsNullOrEmpty(categoryName))
{
var parentCategory = allCategories.ContainsKey(categoryName)
//try find category by full name with all parent category names
? allCategories[categoryName]
//try find category by name
: allCategories.Values.FirstOrDefault(c => c.Name.Equals(categoryName, StringComparison.InvariantCulture));

if (parentCategory != null)
{
category.ParentCategoryId = parentCategory.Id;
isParentCategorySet = true;
}
else
{
isParentCategoryExists = false;
}
}
}
break;
case "Picture":
var picture = LoadPicture(manager.GetProperty("Picture").StringValue, category.Name, isNew ? null : (int?)category.PictureId);
if (picture != null)
category.PictureId = picture.Id;
break;
case "PageSize":
category.PageSize = property.IntValue;
break;
case "AllowCustomersToSelectPageSize":
category.AllowCustomersToSelectPageSize = property.BooleanValue;
break;
case "PageSizeOptions":
category.PageSizeOptions = property.StringValue;
break;
case "PriceRanges":
category.PriceRanges = property.StringValue;
break;
case "ShowOnHomePage":
category.ShowOnHomePage = property.BooleanValue;
break;
case "IncludeInTopMenu":
category.IncludeInTopMenu = property.BooleanValue;
break;
case "Published":
category.Published = property.BooleanValue;
break;
case "DisplayOrder":
category.DisplayOrder = property.IntValue;
break;
case "SeName":
seName = property.StringValue;
break;
}
}

category.UpdatedOnUtc = DateTime.UtcNow;
return seName;
}

Choose a reason for hiding this comment

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

❌ New issue: Deep, Nested Complexity
UpdateCategoryByXlsx has a nested complexity depth of 5, threshold = 4

Why does this problem occur?

This function contains deeply nested logic such as if statements and/or loops. The deeper the nesting, the lower the code health. Read more.

To ignore this warning click here.

Comment on lines +789 to +1035
out int aid))
{
allAttributeIds.Add(aid);
}
else
{
specificationAttributeManager.ReadFromXlsx(worksheet, endRow,
ExportProductAttribute.ProducAttributeCellOffset);

if (!specificationAttributeManager.IsCaption &&
int.TryParse(
(worksheet.Cells[endRow, specificationAttributeOptionIdCellNum].Value ??
string.Empty).ToString(), out int saoid))
{
allSpecificationAttributeOptionIds.Add(saoid);
}
}
}

endRow++;
continue;
}

if (categoryCellNum > 0)
{
var categoryIds = worksheet.Cells[endRow, categoryCellNum].Value?.ToString() ?? string.Empty;

if (!string.IsNullOrEmpty(categoryIds))
allCategoriesNames.AddRange(categoryIds
.Split(new[] { ";", ">>" }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim())
.Distinct());
}

if (skuCellNum > 0)
{
var sku = worksheet.Cells[endRow, skuCellNum].Value?.ToString() ?? string.Empty;

if (!string.IsNullOrEmpty(sku))
allSku.Add(sku);
}

if (manufacturerCellNum > 0)
{
var manufacturerIds = worksheet.Cells[endRow, manufacturerCellNum].Value?.ToString() ??
string.Empty;
if (!string.IsNullOrEmpty(manufacturerIds))
allManufacturersNames.AddRange(manufacturerIds
.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()));
}

//counting the number of products
productsInFile.Add(endRow);

endRow++;
}

//performance optimization, the check for the existence of the categories in one SQL request
var notExistingCategories = _categoryService.GetNotExistingCategories(allCategoriesNames.ToArray());
if (notExistingCategories.Any())
{
throw new ArgumentException(string.Format(_localizationService.GetResource("Admin.Catalog.Products.Import.CategoriesDontExist"), string.Join(", ", notExistingCategories)));
}

//performance optimization, the check for the existence of the manufacturers in one SQL request
var notExistingManufacturers = _manufacturerService.GetNotExistingManufacturers(allManufacturersNames.ToArray());
if (notExistingManufacturers.Any())
{
throw new ArgumentException(string.Format(_localizationService.GetResource("Admin.Catalog.Products.Import.ManufacturersDontExist"), string.Join(", ", notExistingManufacturers)));
}

//performance optimization, the check for the existence of the product attributes in one SQL request
var notExistingProductAttributes = _productAttributeService.GetNotExistingAttributes(allAttributeIds.ToArray());
if (notExistingProductAttributes.Any())
{
throw new ArgumentException(string.Format(_localizationService.GetResource("Admin.Catalog.Products.Import.ProductAttributesDontExist"), string.Join(", ", notExistingProductAttributes)));
}

//performance optimization, the check for the existence of the specification attribute options in one SQL request
var notExistingSpecificationAttributeOptions = _specificationAttributeService.GetNotExistingSpecificationAttributeOptions(allSpecificationAttributeOptionIds.Where(saoId => saoId != 0).ToArray());
if (notExistingSpecificationAttributeOptions.Any())
{
throw new ArgumentException($"The following specification attribute option ID(s) don't exist - {string.Join(", ", notExistingSpecificationAttributeOptions)}");
}

return new ImportProductMetadata
{
EndRow = endRow,
Manager = manager,
Properties = properties,
ProductsInFile = productsInFile,
ProductAttributeManager = productAttributeManager,
SpecificationAttributeManager = specificationAttributeManager,
SkuCellNum = skuCellNum,
AllSku = allSku,
AllCategoriesNames = allCategoriesNames,
AllManufacturersNames = allManufacturersNames,
AllAttributeIds = allAttributeIds,
AllSpecificationAttributeOptionIds = allSpecificationAttributeOptionIds
};
}

Choose a reason for hiding this comment

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

❌ New issue: Deep, Nested Complexity
PrepareImportProductData has a nested complexity depth of 5, threshold = 4

Why does this problem occur?

This function contains deeply nested logic such as if statements and/or loops. The deeper the nesting, the lower the code health. Read more.

To ignore this warning click here.

Comment on lines +1164 to +1728
IsFeaturedProduct = false,
DisplayOrder = 1
};
_categoryService.InsertProductCategory(productCategory);
}

//delete product categories
var deletedProductCategories = categories.Where(categoryId => !importedCategories.Contains(categoryId))
.Select(categoryId => product.ProductCategories.First(pc => pc.CategoryId == categoryId));
foreach (var deletedProductCategory in deletedProductCategories)
{
_categoryService.DeleteProductCategory(deletedProductCategory);
}
}

tempProperty = metadata.Manager.GetProperty("Manufacturers");
if (tempProperty != null)
{
var manufacturerNames = tempProperty.StringValue;

//manufacturer mappings
var manufacturers = isNew || !allProductsManufacturerIds.ContainsKey(product.Id) ? new int[0] : allProductsManufacturerIds[product.Id];
var importedManufacturers = manufacturerNames.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(x => allManufacturers.First(m => m.Name == x.Trim()).Id).ToList();
foreach (var manufacturerId in importedManufacturers)
{
if (manufacturers.Any(c => c == manufacturerId))
continue;

var productManufacturer = new ProductManufacturer
{
ProductId = product.Id,
ManufacturerId = manufacturerId,
IsFeaturedProduct = false,
DisplayOrder = 1
};
_manufacturerService.InsertProductManufacturer(productManufacturer);
}

//delete product manufacturers
var deletedProductsManufacturers = manufacturers.Where(manufacturerId => !importedManufacturers.Contains(manufacturerId))
.Select(manufacturerId => product.ProductManufacturers.First(pc => pc.ManufacturerId == manufacturerId));
foreach (var deletedProductManufacturer in deletedProductsManufacturers)
{
_manufacturerService.DeleteProductManufacturer(deletedProductManufacturer);
}
}

tempProperty = metadata.Manager.GetProperty("ProductTags");
if (tempProperty != null)
{
var productTags = tempProperty.StringValue.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToArray();

//product tag mappings
_productTagService.UpdateProductTags(product, productTags);
}

var picture1 = DownloadFile(metadata.Manager.GetProperty("Picture1")?.StringValue, downloadedFiles);
var picture2 = DownloadFile(metadata.Manager.GetProperty("Picture2")?.StringValue, downloadedFiles);
var picture3 = DownloadFile(metadata.Manager.GetProperty("Picture3")?.StringValue, downloadedFiles);

productPictureMetadata.Add(new ProductPictureMetadata
{
ProductItem = product,
Picture1Path = picture1,
Picture2Path = picture2,
Picture3Path = picture3,
IsNew = isNew
});

lastLoadedProduct = product;

//update "HasTierPrices" and "HasDiscountsApplied" properties
//_productService.UpdateHasTierPricesProperty(product);
//_productService.UpdateHasDiscountsApplied(product);
}

if (_mediaSettings.ImportProductImagesUsingHash && _pictureService.StoreInDb && _dataProvider.SupportedLengthOfBinaryHash() > 0)
ImportProductImagesUsingHash(productPictureMetadata, allProductsBySku);
else
ImportProductImagesUsingServices(productPictureMetadata);

foreach (var downloadedFile in downloadedFiles)
{
if (!_fileProvider.FileExists(downloadedFile))
continue;

try
{
_fileProvider.DeleteFile(downloadedFile);
}
catch
{

}
}

//activity log
_customerActivityService.InsertActivity("ImportProducts", string.Format(_localizationService.GetResource("ActivityLog.ImportProducts"), metadata.CountProductsInFile));
}
}

Choose a reason for hiding this comment

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

❌ New issue: Deep, Nested Complexity
ImportProductsFromXlsx has a nested complexity depth of 4, threshold = 4

Why does this problem occur?

This function contains deeply nested logic such as if statements and/or loops. The deeper the nesting, the lower the code health. Read more.

To ignore this warning click here.

Comment on lines +1873 to +1991
var allColumnsAreEmpty = manager.GetProperties
.Select(property => worksheet.Cells[iRow, property.PropertyOrderPosition])
.All(cell => cell == null || cell.Value == null || string.IsNullOrEmpty(cell.Value.ToString()));

if (allColumnsAreEmpty)
break;

manager.ReadFromXlsx(worksheet, iRow);

var manufacturer = _manufacturerService.GetManufacturerById(manager.GetProperty("Id").IntValue);

var isNew = manufacturer == null;

manufacturer = manufacturer ?? new Manufacturer();

if (isNew)
{
manufacturer.CreatedOnUtc = DateTime.UtcNow;

//default values
manufacturer.PageSize = _catalogSettings.DefaultManufacturerPageSize;
manufacturer.PageSizeOptions = _catalogSettings.DefaultManufacturerPageSizeOptions;
manufacturer.Published = true;
manufacturer.AllowCustomersToSelectPageSize = true;
}

var seName = string.Empty;

foreach (var property in manager.GetProperties)
{
switch (property.PropertyName)
{
case "Name":
manufacturer.Name = property.StringValue;
break;
case "Description":
manufacturer.Description = property.StringValue;
break;
case "ManufacturerTemplateId":
manufacturer.ManufacturerTemplateId = property.IntValue;
break;
case "MetaKeywords":
manufacturer.MetaKeywords = property.StringValue;
break;
case "MetaDescription":
manufacturer.MetaDescription = property.StringValue;
break;
case "MetaTitle":
manufacturer.MetaTitle = property.StringValue;
break;
case "Picture":
var picture = LoadPicture(manager.GetProperty("Picture").StringValue, manufacturer.Name, isNew ? null : (int?)manufacturer.PictureId);

if (picture != null)
manufacturer.PictureId = picture.Id;

break;
case "PageSize":
manufacturer.PageSize = property.IntValue;
break;
case "AllowCustomersToSelectPageSize":
manufacturer.AllowCustomersToSelectPageSize = property.BooleanValue;
break;
case "PageSizeOptions":
manufacturer.PageSizeOptions = property.StringValue;
break;
case "PriceRanges":
manufacturer.PriceRanges = property.StringValue;
break;
case "Published":
manufacturer.Published = property.BooleanValue;
break;
case "DisplayOrder":
manufacturer.DisplayOrder = property.IntValue;
break;
case "SeName":
seName = property.StringValue;
break;
}
}

manufacturer.UpdatedOnUtc = DateTime.UtcNow;

if (isNew)
_manufacturerService.InsertManufacturer(manufacturer);
else
_manufacturerService.UpdateManufacturer(manufacturer);

//search engine name
if (setSeName)
_urlRecordService.SaveSlug(manufacturer, manufacturer.ValidateSeName(seName, manufacturer.Name, true), 0);

iRow++;
}

//activity log
_customerActivityService.InsertActivity("ImportManufacturers",
string.Format(_localizationService.GetResource("ActivityLog.ImportManufacturers"), iRow - 2));
}
}

Choose a reason for hiding this comment

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

❌ New issue: Deep, Nested Complexity
ImportManufacturersFromXlsx has a nested complexity depth of 4, threshold = 4

Why does this problem occur?

This function contains deeply nested logic such as if statements and/or loops. The deeper the nesting, the lower the code health. Read more.

To ignore this warning click here.

@@ -0,0 +1,2170 @@
using System;

Choose a reason for hiding this comment

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

❌ New issue: Low Cohesion
This module has at least 4 different responsibilities amongst its 32 functions, threshold = 3

Why does this problem occur?

Cohesion is calculated using the LCOM4 metric. Low cohesion means that the module/class has multiple unrelated responsibilities, doing too many things and breaking the Single Responsibility Principle. Read more.

To ignore this warning click here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant