Skip to content

Commit 36a5271

Browse files
authored
Merge pull request #124 from samuelzedec/develop
fix: Correções de algumas issues do SonarCloud
2 parents 3c427a1 + 3d9af31 commit 36a5271

File tree

16 files changed

+84
-110
lines changed

16 files changed

+84
-110
lines changed

src/Riber.Domain/Constants/Messages/Entities/ProductErrors.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ public static class ProductErrors
99
public const string PriceEmpty = "O produto deve ter um preço.";
1010
public const string PriceGreaterThanZero = "O preço do produto deve ser maior que zero.";
1111
public const string InvalidCategory = "O produto deve pertencer a uma categoria.";
12+
public const string InvalidCompany = "O produto deve pertencer a uma empresa.";
1213
}

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 & 13 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
@@ -80,10 +75,9 @@ public static Product Create(
8075
if (categoryId == Guid.Empty)
8176
throw new IdentifierNullException(ProductErrors.InvalidCategory);
8277

83-
if (companyId == Guid.Empty)
84-
throw new IdentifierNullException(ProductErrors.InvalidCategory);
85-
86-
return new Product(name, description, price, categoryId, companyId, imageId);
78+
return companyId == Guid.Empty
79+
? throw new IdentifierNullException(ProductErrors.InvalidCompany)
80+
: new Product(name, description, price, categoryId, companyId, imageId);
8781
}
8882

8983
#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,

0 commit comments

Comments
 (0)