Skip to content
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
66 changes: 66 additions & 0 deletions SynonymsAPI/Services/badClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1797,6 +1797,72 @@ public virtual int ImportNewsletterSubscribersFromTxt(Stream stream)
return count;
}

public virtual int ImportNewsletterSubscribersFromTxt2(Stream stream)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ℹ Getting worse: Lines of Code in a Single File
The lines of code increases from 1661 to 1716, improve code health by reducing it to 1000

Why does this problem occur?

The number of Lines of Code in a single file. More Lines of Code lowers the code health. Read more.

To ignore this warning click here.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Getting better: Overall Code Complexity
The mean cyclomatic complexity decreases from 12.66 to 12.52, threshold = 4

Why does this problem occur?

This file has many conditional statements (e.g. if, for, while) across its implementation, leading to lower code health. Avoid adding more conditionals. Read more.

{
var count = 0;
using (var reader = new StreamReader(stream))
{
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
if (string.IsNullOrWhiteSpace(line))
continue;
var tmp = line.Split(',');

string email;
var isActive = true;
var storeId = _storeContext.CurrentStore.Id;
//parse
if (tmp.Length == 1)
{
//"email" only
email = tmp[0].Trim();
}
else if (tmp.Length == 2)
{
//"email" and "active" fields specified
email = tmp[0].Trim();
isActive = bool.Parse(tmp[1].Trim());
}
else if (tmp.Length == 3)
{
//"email" and "active" and "storeId" fields specified
email = tmp[0].Trim();
isActive = bool.Parse(tmp[1].Trim());
storeId = int.Parse(tmp[2].Trim());
}
else
throw new NopException("Wrong file format");

//import
var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmailAndStoreId(email, storeId);
if (subscription != null)
{
subscription.Email = email;
subscription.Active = isActive;
_newsLetterSubscriptionService.UpdateNewsLetterSubscription(subscription);
}
else
{
subscription = new NewsLetterSubscription
{
Active = isActive,
CreatedOnUtc = DateTime.UtcNow,
Email = email,
StoreId = storeId,
NewsLetterSubscriptionGuid = Guid.NewGuid()
};
_newsLetterSubscriptionService.InsertNewsLetterSubscription(subscription);
}

count++;
}
}

return count;
}


/// <summary>
/// Import states from TXT file
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Test/bin/Debug/net6.0/nunit_random_seed.tmp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1030685833
1743653074