Skip to content

Commit fbba649

Browse files
committed
fix: Correções de algumas issues do SonarCloud
1 parent 02c533b commit fbba649

File tree

14 files changed

+81
-112
lines changed

14 files changed

+81
-112
lines changed

src/Riber.Domain/Entities/BaseEntity.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ namespace Riber.Domain.Entities;
66
/// Representa uma entidade base abstrata que fornece funcionalidades comuns para entidades de domínio.
77
/// Esta classe inclui um identificador, gerenciamento de eventos de domínio e mecanismos de comparação de igualdade.
88
/// </summary>
9+
#pragma warning disable CA1067
910
public abstract class BaseEntity(Guid id) : IEquatable<BaseEntity>
11+
#pragma warning restore CA1067
1012
{
1113
#region Private Members
1214

src/Riber.Domain/Entities/Company.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,9 @@ public sealed class Company
2222

2323
#region Constructors
2424

25-
private Company() : base(Guid.Empty)
26-
{
27-
Name = null!;
28-
TaxId = null!;
29-
Email = null!;
30-
Phone = null!;
31-
}
25+
#pragma warning disable CS8618, CA1823
26+
private Company() : base(Guid.Empty) { }
27+
#pragma warning restore CS8618, CA1823
3228

3329
private Company(
3430
CompanyName name,

src/Riber.Domain/Entities/Image.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,10 @@ public sealed class Image : BaseEntity
3333

3434
#region Constructors
3535

36-
private Image() : base(Guid.Empty)
37-
{
38-
Length = 0;
39-
ContentType = string.Empty;
40-
OriginalName = string.Empty;
41-
Key = string.Empty;
42-
Extension = string.Empty;
43-
ShouldDelete = false;
44-
MarkedForDeletionAt = null;
45-
}
36+
#pragma warning disable CS8618, CA1823
37+
private Image() : base(Guid.Empty) { }
38+
#pragma warning restore CS8618, CA1823
39+
4640
private Image(long length, string contentType, string originalName, string key, string extension)
4741
: base(Guid.CreateVersion7())
4842
{

src/Riber.Domain/Entities/Invitation.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,9 @@ public sealed class Invitation
2525

2626
#region Constructors
2727

28-
private Invitation() : base(Guid.CreateVersion7())
29-
{
30-
Email = null!;
31-
CompanyId = Guid.Empty;
32-
Role = null!;
33-
IsUsed = false;
34-
Position = default;
35-
Permissions = string.Empty;
36-
CreatedByUserId = Guid.Empty;
37-
ExpiresAt = default;
38-
Token = null!;
39-
}
28+
#pragma warning disable CS8618, CA1823
29+
private Invitation() : base(Guid.CreateVersion7()) { }
30+
#pragma warning restore CS8618, CA1823
4031

4132
private Invitation(
4233
Email email,

src/Riber.Domain/Entities/Order.cs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace Riber.Domain.Entities;
77

8-
public sealed class Order
8+
public sealed class Order
99
: TenantEntity, IAggregateRoot, IHasRandomToken
1010
{
1111
#region Properties
@@ -16,27 +16,24 @@ public sealed class Order
1616
public decimal SubTotal => _items.Sum(x => x.SubTotal);
1717
public decimal TotalDiscounts => _items.Sum(x => x.DiscountAmount);
1818
public decimal TotalAmount => SubTotal - TotalDiscounts;
19-
19+
2020
#endregion
21-
21+
2222
#region Navigation Properties
23-
23+
2424
public Company Company { get; private set; } = null!;
2525
public User Attendant { get; private set; } = null!;
2626
public IReadOnlyCollection<OrderItem> ItemsReadOnly => _items.AsReadOnly();
27-
27+
2828
#endregion
29-
29+
3030
#region Constructors
3131

32-
private Order() : base(Guid.Empty)
33-
{
34-
Token = null!;
35-
CompanyId = Guid.Empty;
36-
AttendantId = Guid.Empty;
37-
}
32+
#pragma warning disable CS8618, CA1823
33+
private Order() : base(Guid.Empty) { }
34+
#pragma warning restore CS8618, CA1823
3835

39-
private Order(Guid companyId, Guid attendantId)
36+
private Order(Guid companyId, Guid attendantId)
4037
: base(Guid.CreateVersion7())
4138
{
4239
CompanyId = companyId;
@@ -45,11 +42,11 @@ private Order(Guid companyId, Guid attendantId)
4542
}
4643

4744
#endregion
48-
45+
4946
#region Factories
5047

5148
public static Order Create(Guid companyId, Guid attendantId)
5249
=> new(companyId, attendantId);
53-
50+
5451
#endregion
5552
}

src/Riber.Domain/Entities/OrderItem.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,9 @@ public sealed class OrderItem
3333

3434
#region Constructors
3535

36-
private OrderItem() : base(Guid.Empty)
37-
{
38-
OrderId = Guid.Empty;
39-
ProductId = Guid.Empty;
40-
ProductName = string.Empty;
41-
UnitPrice = Money.Zero();
42-
Quantity = Quantity.Zero();
43-
}
36+
#pragma warning disable CS8618, CA1823
37+
private OrderItem() : base(Guid.Empty) { }
38+
#pragma warning restore CS8618, CA1823
4439

4540
private OrderItem(
4641
Guid orderId,

src/Riber.Domain/Entities/Product.cs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,9 @@ public sealed class Product
3232

3333
#region Constructors
3434

35-
private Product() : base(Guid.Empty)
36-
{
37-
Name = string.Empty;
38-
Description = string.Empty;
39-
UnitPrice = null!;
40-
CategoryId = Guid.Empty;
41-
IsActive = false;
42-
CompanyId = Guid.Empty;
43-
}
35+
#pragma warning disable CS8618, CA1823
36+
private Product() : base(Guid.Empty) { }
37+
#pragma warning restore CS8618, CA1823
4438

4539
private Product(
4640
string name,
@@ -57,6 +51,7 @@ private Product(
5751
CompanyId = companyId;
5852
ImageId = imageId;
5953
IsActive = true;
54+
Image = null;
6055
}
6156

6257
#endregion
@@ -77,13 +72,9 @@ public static Product Create(
7772
if (string.IsNullOrWhiteSpace(description))
7873
throw new ProductDescriptionNullException(ProductErrors.DescriptionEmpty);
7974

80-
if (categoryId == Guid.Empty)
81-
throw new IdentifierNullException(ProductErrors.InvalidCategory);
82-
83-
if (companyId == Guid.Empty)
84-
throw new IdentifierNullException(ProductErrors.InvalidCategory);
85-
86-
return new Product(name, description, price, categoryId, companyId, imageId);
75+
return categoryId == Guid.Empty
76+
? throw new IdentifierNullException(ProductErrors.InvalidCategory)
77+
: new Product(name, description, price, categoryId, companyId, imageId);
8778
}
8879

8980
#endregion

src/Riber.Domain/Entities/ProductCategory.cs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,9 @@ public sealed class ProductCategory
2626

2727
#region Constructors
2828

29-
private ProductCategory() : base(Guid.Empty)
30-
{
31-
Name = string.Empty;
32-
Description = string.Empty;
33-
Code = string.Empty;
34-
IsActive = false;
35-
CompanyId = Guid.Empty;
36-
}
29+
#pragma warning disable CS8618, CA1823
30+
private ProductCategory() : base(Guid.Empty) { }
31+
#pragma warning restore CS8618, CA1823
3732

3833
private ProductCategory(
3934
string name,
@@ -64,10 +59,9 @@ public static ProductCategory Create(
6459
if (string.IsNullOrWhiteSpace(code))
6560
throw new ProductCategoryCodeNullException(CategoryErrors.CodeEmpty);
6661

67-
if (companyId == Guid.Empty)
68-
throw new IdentifierNullException(CompanyErrors.Invalid);
69-
70-
return new ProductCategory(name, description, code, companyId);
62+
return companyId == Guid.Empty
63+
? throw new IdentifierNullException(CompanyErrors.Invalid)
64+
: new ProductCategory(name, description, code, companyId);
7165
}
7266

7367
#endregion
@@ -80,12 +74,12 @@ public void UpdateDetails(string name, string? description)
8074
throw new ProductCategoryNameNullException(CategoryErrors.NameEmpty);
8175

8276
Name = name;
83-
if(description is not null)
77+
if (description is not null)
8478
Description = description;
8579
}
8680

8781
public void Activate() => IsActive = true;
8882
public void Deactivate() => IsActive = false;
8983

9084
#endregion
91-
}
85+
}

src/Riber.Domain/Entities/User.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,9 @@ public sealed class User
2929

3030
#region Constructors
3131

32-
public User() : base(Guid.Empty)
33-
{
34-
FullName = null!;
35-
TaxId = null!;
36-
CompanyId = null!;
37-
IsActive = false;
38-
}
32+
#pragma warning disable CS8618, CA1823
33+
public User() : base(Guid.Empty) { }
34+
#pragma warning restore CS8618, CA1823
3935

4036
private User(
4137
FullName fullName,

src/Riber.Domain/Validators/DocumentValidator/CnpjValidator.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@ public void IsValid(string document)
2121
if (cnpj.Distinct().Count() == 1)
2222
throw new InvalidCnpjException(CnpjErrors.OnlyRepeatedDigits);
2323

24-
int[] digits = cnpj
25-
.Select(c => c - '0')
26-
.ToArray();
24+
int[] digits = [.. cnpj.Select(c => c - '0')];
2725

2826
// Cálculo do primeiro dígito verificador
29-
int[] multiplier1 = { 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2 };
27+
int[] multiplier1 = [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
3028
int sum = 0;
3129

3230
for (int i = 0; i < 12; i++)
@@ -39,7 +37,7 @@ public void IsValid(string document)
3937
throw new InvalidCnpjException(CnpjErrors.Invalid);
4038

4139
// Cálculo do segundo dígito verificador
42-
int[] multiplier2 = { 6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2 };
40+
int[] multiplier2 = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
4341
sum = 0;
4442

4543
for (int i = 0; i < 13; i++)
@@ -66,7 +64,7 @@ public string Sanitize(string document)
6664
}
6765

6866
public static string Format(string document)
69-
=> $"{document.Substring(0, 2)}.{document.Substring(2, 3)}.{document.Substring(5, 3)}/{document.Substring(8, 4)}-{document.Substring(12, 2)}";
67+
=> $"{document[..2]}.{document.Substring(2, 3)}.{document.Substring(5, 3)}/{document.Substring(8, 4)}-{document.Substring(12, 2)}";
7068

7169
#endregion
7270
}

0 commit comments

Comments
 (0)